ThInf-HOME

  1. Einführung

  2. Zufluss und Abfluss vn Mitteln bei der Rentenkasse

  3. Testausdruck mit Rentenkasse

  4. Quellkode mit Rentenkasse

  5. Grafische Ausgabe

  6. Einlesen über eine Datei

  7. Übungsaufgaben


I-PROGRAMMIEREN1 WS 0203 - Vorlesung mit Übung
VL13: Projekt EARTHSIMULATOR1 - Berechnungen II

Achtung : Dieses Skript gibt den mündlichen Vortrag nur teilweise wieder !!!

AUTHOR: Gerd Döben-Henisch
DATE OF FIRST GENERATION: Jan-6,2003
DATE OF LAST CHANGE: Jan-6, 2003
EMAIL: Gerd Döben-Henisch



1. Einführung


Nachdem nun eine einfache Simulation demographischer Prozesse zur Verfügung steht, sollen nun zum Abschluss des kleinen Projekts noch folgende Teilaufgaben gelöst werden:

  1. Simulation des jährlichen Zuflusses und Abflusses in die Rentenkasse RK


  2. Grafische Ausgabe der Ergebnisse


  3. Einlesen von Daten aus einer Datei


Die benutzten C-Quellen liegen als folgende Dateien bereit:


START

2. Zufluss und Abfluss in die Rentenkasse


Aus der vorausgehenden Systemanalyse (siehe zur Erinnerung nachfolgendes Schaubild) ist bekannt, dass die Zuflüsse zur Rentenkasse RK im Modell aus zwei Quellen stammen: den unselbständig Beschäftigten und zu gleichen Teilen von den Arbeitgebern (AG). Als Abflüsse werden im Modell bislang angenommen die Zahlungen an die Rentner1 (dass in der 'realen Welt' die Dinge etwas komplizierter liegen sei hier der Vollständigkeithalber nochmals erwähnt; entsprechende Verfeinerungen wären bei einem grösseren Einsatz dieses Modells dann noch anzubringen).



earth1
Wichtige Grössen und funktionale Beziehungen des EARTHSIM1 für ein einzelnes Land im Überblick



Um die Grösse Rentenkasse RK berechnen zu können, muss die bisherige Übergangsfunktion f = compute_phase_shift() o compute_phase_flow() erweitert werden um Funktionen zur Berechnung des Zuflusses und des Abflusses von Geldern zu und von der Rentenkasse RK. Nennt man diese Funktionen compute_rk_in() bzw. compute_rk_out(), dann bekommt man als neue Übergangsfunktion:

f2 = compute_phase_shift() o compute_phase_flow() o compute_rk_in() o compute_rk_out()



transfer2
Erweiterte Übergangsfunktion mit Berechnung für RK



Für die Definition von compute_rk_in() und compute_rk_out() muss man zunächst wieder zusammenstellen, von welchen Werten diese Funktionen abhängen.

Im Fall von compute_rk_in() gilt, dass Einzahler die Arbeitgeber und die unselbständig Beschäftigten sind. Da sich der Anteil der Arbeitgeber vollständig nach dem Anteil der Beschäftigten richtet, genügt es, diesen zu analysieren.

Die Anzahl der unselbständig Beschäftigten ergibt sich innerhalb einer Phase als Prozentsatz (percentage_of_number) der Gesamtzahl (number) der jeweiligen Phase. Jeder dieser Beschäftigten zahlt einen bestimmten Prozentsatz ( RK_paymen_percentage) seines jährlichen Bruttoeinkommens (actual_yearly_income) an die Rentenkasse RK. Daraus ergibt sich für eine Phase beschränkt auf die Beschäftigten die Formel:

RK.in += number * employed.percentage_of_number * employed.RK_payment_percentage * employed.actual_yearly_income

Zusätzlich muss der gleiche Betrag vom Konto der Arbeitgeber AG abgebucht werden.

Im Fall von compute_rk_out() gilt, dass es nur die Empfänger retired_persons1 gibt. Im Modell wird vereinfachend angenommen, dass sich der Prozentsatz der Rentner1 aus dem Prozentsatz der zuletzt Beschäftigten herleitet, also retired_persons1.percentage_of_number = employed.percentage_of_number (aus vorausgehender Phase). Dieser Prozentsatz wird dann an die nächsten Phasen weitergereicht. Ebenso wird das vormalige Jahreseinkommen am Jahreseinkommen der zuletzt Beschäftigten orientiert, also retired_persons1.former_yearly_income = employed.actual_yearly_income (aus vorausgehender Phase). Man erhält dann die Formel:

RK.out -= number * retired_persons1.percentage_of_number * retired_persons1.RK_payment_percentage * retired_persons1.former_yearly_income

Im folgenden wieder ein Testausdruck für eine kleine Modellpopulation. Man beachte, dass es sich bei der Ein- und Eusgabe noch um eine experimentelle Testversion handelt; weitere daten, die noch im Programm verfügbar sind, wurden nicht ausgedruckt.



START

3. Testausdruck mit Rentenkasse



gerd@goedel:~/WEB-MATERIAL/fh/I-PROGR1/I-PROGR1-TH/VL13> ./esim5
Kontrolle : Phasezahlen 0 - 5
Kontrolle : Phasezahlen 6 - 15
Kontrolle : Phasezahlen 16 - 25
Kontrolle : Phasezahlen 26 - 35
Kontrolle : Phasezahlen 36 - 45
Kontrolle : Phasezahlen 46 - 55
Kontrolle : Phasezahlen 56 - 65
Kontrolle : Phasezahlen 66 - 75
Kontrolle : Phasezahlen 76 - 85
Kontrolle : Phasezahlen 86 - 95
Kontrolle : Phasezahlen 96 - 105
Kontrolle : Phasezahlen 106 - 115
Kontrolle : Phasezahlen 116 - 125
Kontrolle : Phasezahlen 126 - 135
Kontrolle : Phasezahlen 136 - 145
Kontrolle : Phasezahlen 146 - 155
Kontrolle : Phasezahlen 156 - 165
Kontrolle : Phasezahlen 166 - 175
Kontrolle : Phasezahlen 176 - 185
Kontrolle : Phasezahlen 186 - 195

***** BEGINN EINGABE VON STARTWERTEN  *****
********* BEGINN EINGABE ALLGEMEINER STARTWERTE  *******************


GENERAL:  Anzahl Phasen (int) (MAXIMUM = 20)
: 4
PHASE:  Max.Anzahl Phasen = 4

GENERAL:  Anzahl Durchgaenge/ Jahre (int)
: 6
PHASE:  Anzahl Durchgaenge/Jahre = 6

GENERAL: Beginn der Pensionierung1 (Phase)
: 3
PHASE:  Beginn der Pensionierung1  = 3

STARTWERT fuer RK : 0

STARTWERT fuer AG : 0


********* BEGINN EINGABE SPEZIELLER STARTWERTE FUER PHASE  *******************
Phasezahlen 0 - 5
*****************************************************************************

PHASE:  Anzahl Mitglieder (Vorher) = 0.00

PHASE: Anzahl Mitglieder  = 1000
PHASE:  Anzahl Mitglieder Neu = 1000.00

PHASE: Proz-Maenner Vorher (Gleitkomma) = 0.00
PHASE: Proz-Maenner (Gleitkomma) = 50
PHASE:  Proz-Maenner Neu = 50.00
PHASE:  Proz-Frauen Neu = 50.00

PHASE: Geburtenrate (Gleitkomma) = 0.00
PHASE: Geburtenrate (Gleitkomma) = 0
PHASE:  Geburtenrate Neu = 0.00

PHASE: Sterberate (Gleitkomma) = 0.00
PHASE: Sterberate (Gleitkomma) = 0
PHASE:  Sterberate Neu = 0.00

PHASE: Zuwanderung (Gleitkomma) = 0.00
PHASE: Zuwanderung (Gleitkomma) = 0
PHASE: Zuwanderung  Neu = 0.00

PHASE: Abwanderung (Gleitkomma) = 0.00
PHASE: Abwanderung (Gleitkomma) = 0
PHASE: Abwanderung  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER RENTEN-STARTWERTE FUER PHASE  *******************
Phasezahlen 0 - 5
*****************************************************************************

PHASE: Proz-Anteil Beschaeftigter  (Vorher) = 0.00

PHASE: Proz-Anteil Beschaeftigter  = 0
PHASE:  Proz-Anteil Beschaeftigter Neu  = 0.00

PHASE: Jaehrl. Bruttoeinkommen bisher (Gleitkomma) = 0.00
PHASE:  Jaehrl. Bruttoeinkommen (Gleitkomma) = 0
PHASE:  Jaehrl. Bruttoeinkommen  Neu = 0.00

PHASE: Proz-Anteil RK-Zahlung bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Zahlung (Gleitkomma) = 0
PHASE:  Proz-Anteil RK-Zahlung   Neu = 0.00

PHASE: Proz-Anteil RK-Einkommen bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Einkommen (Gleitkomma) = 0
PHASE:  Proz-Anteil RK-Einkommen  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER STARTWERTE FUER PHASE  *******************
Phasezahlen 6 - 15
*****************************************************************************

PHASE:  Anzahl Mitglieder (Vorher) = 0.00

PHASE: Anzahl Mitglieder  = 2000
PHASE:  Anzahl Mitglieder Neu = 2000.00

PHASE: Proz-Maenner Vorher (Gleitkomma) = 0.00
PHASE: Proz-Maenner (Gleitkomma) = 50
PHASE:  Proz-Maenner Neu = 50.00
PHASE:  Proz-Frauen Neu = 50.00

PHASE: Geburtenrate (Gleitkomma) = 0.00
PHASE: Geburtenrate (Gleitkomma) = 0
PHASE:  Geburtenrate Neu = 0.00

PHASE: Sterberate (Gleitkomma) = 0.00
PHASE: Sterberate (Gleitkomma) = 0
PHASE:  Sterberate Neu = 0.00

PHASE: Zuwanderung (Gleitkomma) = 0.00
PHASE: Zuwanderung (Gleitkomma) = 0
PHASE: Zuwanderung  Neu = 0.00

PHASE: Abwanderung (Gleitkomma) = 0.00
PHASE: Abwanderung (Gleitkomma) = 0
PHASE: Abwanderung  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER RENTEN-STARTWERTE FUER PHASE  *******************
Phasezahlen 6 - 15
*****************************************************************************

PHASE: Proz-Anteil Beschaeftigter  (Vorher) = 0.00

PHASE: Proz-Anteil Beschaeftigter  = 20
PHASE:  Proz-Anteil Beschaeftigter Neu  = 20.00

PHASE: Jaehrl. Bruttoeinkommen bisher (Gleitkomma) = 0.00
PHASE:  Jaehrl. Bruttoeinkommen (Gleitkomma) = 12000
PHASE:  Jaehrl. Bruttoeinkommen  Neu = 12000.00

PHASE: Proz-Anteil RK-Zahlung bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Zahlung (Gleitkomma) = 14
PHASE:  Proz-Anteil RK-Zahlung   Neu = 14.00

PHASE: Proz-Anteil RK-Einkommen bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Einkommen (Gleitkomma) = 0
PHASE:  Proz-Anteil RK-Einkommen  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER STARTWERTE FUER PHASE  *******************
Phasezahlen 16 - 25
*****************************************************************************

PHASE:  Anzahl Mitglieder (Vorher) = 0.00

PHASE: Anzahl Mitglieder  = 3000
PHASE:  Anzahl Mitglieder Neu = 3000.00

PHASE: Proz-Maenner Vorher (Gleitkomma) = 0.00
PHASE: Proz-Maenner (Gleitkomma) = 50
PHASE:  Proz-Maenner Neu = 50.00
PHASE:  Proz-Frauen Neu = 50.00

PHASE: Geburtenrate (Gleitkomma) = 0.00
PHASE: Geburtenrate (Gleitkomma) = 1.2
PHASE:  Geburtenrate Neu = 1.20

PHASE: Sterberate (Gleitkomma) = 0.00
PHASE: Sterberate (Gleitkomma) = 0
PHASE:  Sterberate Neu = 0.00

PHASE: Zuwanderung (Gleitkomma) = 0.00
PHASE: Zuwanderung (Gleitkomma) = 0
PHASE: Zuwanderung  Neu = 0.00

PHASE: Abwanderung (Gleitkomma) = 0.00
PHASE: Abwanderung (Gleitkomma) = 0
PHASE: Abwanderung  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER RENTEN-STARTWERTE FUER PHASE  *******************
Phasezahlen 16 - 25
*****************************************************************************

PHASE: Proz-Anteil Beschaeftigter  (Vorher) = 0.00

PHASE: Proz-Anteil Beschaeftigter  = 45
PHASE:  Proz-Anteil Beschaeftigter Neu  = 45.00

PHASE: Jaehrl. Bruttoeinkommen bisher (Gleitkomma) = 0.00
PHASE:  Jaehrl. Bruttoeinkommen (Gleitkomma) = 25000
PHASE:  Jaehrl. Bruttoeinkommen  Neu = 25000.00

PHASE: Proz-Anteil RK-Zahlung bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Zahlung (Gleitkomma) = 14
PHASE:  Proz-Anteil RK-Zahlung   Neu = 14.00

PHASE: Proz-Anteil RK-Einkommen bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Einkommen (Gleitkomma) = 0
PHASE:  Proz-Anteil RK-Einkommen  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER STARTWERTE FUER PHASE  *******************
Phasezahlen 26 - 35
*****************************************************************************

PHASE:  Anzahl Mitglieder (Vorher) = 0.00

PHASE: Anzahl Mitglieder  = 2300
PHASE:  Anzahl Mitglieder Neu = 2300.00

PHASE: Proz-Maenner Vorher (Gleitkomma) = 0.00
PHASE: Proz-Maenner (Gleitkomma) = 50
PHASE:  Proz-Maenner Neu = 50.00
PHASE:  Proz-Frauen Neu = 50.00

PHASE: Geburtenrate (Gleitkomma) = 0.00
PHASE: Geburtenrate (Gleitkomma) = 1.0
PHASE:  Geburtenrate Neu = 1.00

PHASE: Sterberate (Gleitkomma) = 0.00
PHASE: Sterberate (Gleitkomma) = 0
PHASE:  Sterberate Neu = 0.00

PHASE: Zuwanderung (Gleitkomma) = 0.00
PHASE: Zuwanderung (Gleitkomma) = 0
PHASE: Zuwanderung  Neu = 0.00

PHASE: Abwanderung (Gleitkomma) = 0.00
PHASE: Abwanderung (Gleitkomma) = 0
PHASE: Abwanderung  Neu = 0.00


********* BEGINN EINGABE SPEZIELLER RENTEN-STARTWERTE FUER PHASE  *******************
Phasezahlen 26 - 35
*****************************************************************************

PHASE: Proz-Anteil Beschaeftigter  (Vorher) = 0.00

PHASE: Proz-Anteil Beschaeftigter  = 25
PHASE:  Proz-Anteil Beschaeftigter Neu  = 25.00

PHASE: Jaehrl. Bruttoeinkommen bisher (Gleitkomma) = 0.00
PHASE:  Jaehrl. Bruttoeinkommen (Gleitkomma) = 20000
PHASE:  Jaehrl. Bruttoeinkommen  Neu = 20000.00

PHASE: Proz-Anteil RK-Zahlung bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Zahlung (Gleitkomma) = 14
PHASE:  Proz-Anteil RK-Zahlung   Neu = 14.00

PHASE: Proz-Anteil RK-Einkommen bisher (Gleitkomma) = 0.00
PHASE:   Proz-Anteil RK-Einkommen (Gleitkomma) = 50
PHASE:  Proz-Anteil RK-Einkommen  Neu = 50.00


GEBURTEN = 2950.000000

***** BEGINN AUSGABE AKTUELLE STATUSWERTE *****

YEAR = 0 --- POP = 11250.00 --- RK.in = 14096600.00 --- RK.out = 7048300.00
AKTUELLER STATUS von RK IN = 14096600.00 , OUT = 14625000.00,  SUMME = -528400.00
AKTUELLER STATUS von AG IN = 0.00 , OUT = 7048300.00,  SUMME = -7048300.00

GEBURTEN = 3040.000000

***** BEGINN AUSGABE AKTUELLE STATUSWERTE *****

YEAR = 1 --- POP = 14290.00 --- RK.in = 14500174.00 --- RK.out = 7250087.00
AKTUELLER STATUS von RK IN = 28596774.00 , OUT = 30881250.00,  SUMME = -2284476.00
AKTUELLER STATUS von AG IN = 0.00 , OUT = 14298387.00,  SUMME = -14298387.00

GEBURTEN = 3129.000000


***** BEGINN AUSGABE AKTUELLE STATUSWERTE *****

YEAR = 2 --- POP = 17419.00 --- RK.in = 15297455.00 --- RK.out = 7648727.50
AKTUELLER STATUS von RK IN = 43894228.00 , OUT = 48716248.00,  SUMME = -4822020.00
AKTUELLER STATUS von AG IN = 0.00 , OUT = 21947114.00,  SUMME = -21947114.00

GEBURTEN = 3244.966797


***** BEGINN AUSGABE AKTUELLE STATUSWERTE *****

YEAR = 3 --- POP = 20663.97 --- RK.in = 16532970.00 --- RK.out = 8266485.00
AKTUELLER STATUS von RK IN = 60427200.00 , OUT = 68107152.00,  SUMME = -7679952.00
AKTUELLER STATUS von AG IN = 0.00 , OUT = 30213600.00,  SUMME = -30213600.00

GEBURTEN = 3408.864014

***** BEGINN AUSGABE AKTUELLE STATUSWERTE *****

YEAR = 4 --- POP = 24072.83 --- RK.in = 18232964.00 --- RK.out = 9116482.00
AKTUELLER STATUS von RK IN = 78660160.00 , OUT = 89077960.00,  SUMME = -10417800.00
AKTUELLER STATUS von AG IN = 0.00 , OUT = 39330080.00,  SUMME = -39330080.00

GEBURTEN = 3636.075439


***** BEGINN AUSGABE AKTUELLE STATUSWERTE *****

YEAR = 5 --- POP = 27708.91 --- RK.in = 20413802.00 --- RK.out = 10206901.00
AKTUELLER STATUS von RK IN = 99073960.00 , OUT = 111710024.00,  SUMME = -12636064.00
AKTUELLER STATUS von AG IN = 0.00 , OUT = 49536980.00,  SUMME = -49536980.00

gerd@goedel:~/WEB-MATERIAL/fh/I-PROGR1/I-PROGR1-TH/VL1



START

4. Quellkode mit Rentenkasse



/************************************
 *
 * esim5.h
 *
 * author: gdh
 * first: dec-09,02
 * last: jan-06.03
 * idea: Headerdatei zum Hauptprogramm esim5.c
 *
 **************************************************/

#define COUNTRY_PHASE_NUMBER 20            /* Maximale Obergrenze fuer Phasen. Der Benutzer
					    * kann eine Zahl kleiner als diese waehlen */

#define CURRENCY_STRING_LENGTH 10

struct SIMULATION {

  int max_phase;               /* Innerhalb des Rahmens COUNTRY_PHASE_NUMBER kann der
				* Benutzer eine eigene maximale Phasenzahl waehlen */
  int sim_duration;            /* Anzahl der Jahre, die durchlaufen werden sollen */
  int birth_low;               /* Phase, ab der Frauen Kinder gebaehren koennen */
  int birth_high;               /* Phase, bis zu der Frauen Kinder gebaehren koennen */
  int retirement_begin;         /* Phase, ab dem Rente1 gezahlt wird und angenommen wird, dass die Beschäftigten
				* aus der vorausgehenden Phase zu Rentnern1 werden */

};

struct ACCOUNT {

  float in;
  float out;
  float sum;
  float unit;
  char currency[CURRENCY_STRING_LENGTH];
};

struct PAYER_PAYEE {

  float percentage_of_number;
  float actual_yearly_income;
  float last_yearly_income;
  float former_yearly_income;
  float RK_payment_percentage;
  float RK_income_percentage;
  float AK_payment_percentage;
  float AK_income_percentage;
  float KK_payment_percentage;
  float KK_income_percentage;
  float XRA_payment_percentage;
  float XRA_income_percentage;
  float AG_payment;
  float AG_income;
};

struct PHASE {

  unsigned int interval[2];
  float number;
  float percentage_men;
  float percentage_women;
  float birthrate;
  float deathrate;
  float migration_plus;
  float migration_minus;
  struct PAYER_PAYEE self_employed;
  struct PAYER_PAYEE employed;
  struct PAYER_PAYEE unemployed;
  struct PAYER_PAYEE education;
  struct PAYER_PAYEE retired_persons1;
  struct PAYER_PAYEE retired_persons2;
  struct PAYER_PAYEE sick_persons;
};

extern int input_data_general(struct SIMULATION *);
extern int input_data_account(struct ACCOUNT *, char *s);
extern int output_data_account(struct ACCOUNT *, char *s);
extern int init_data_phase_demographic(struct PHASE *,int);
extern int input_data_phase_pension(struct PHASE *,int);
extern int input_data_phase(struct PHASE *,int);
extern int output_data_phase_head(struct PHASE *,int);
extern int output_data_phase(struct PHASE *,int);
extern  float compute_birth(struct PHASE *,  struct SIMULATION *);
extern int compute_phase_shift(struct PHASE *,  struct SIMULATION *);
extern int compute_phase_flow(struct PHASE *, int);
extern float compute_pop_number(struct PHASE *,  int);
extern float compute_rk_in(struct PHASE *,  int);
extern float compute_rk_out(struct PHASE *,  int, struct SIMULATION *);



/************************************
 *
 * esim5.c
 *
 * author: gdh
 * first: dec-10,02
 * last: jan-06,03
 * idea: Demoprogramm zur Umsetzung der Anforderungen an
 *       EARTHSIMULATOR1
 *
 *  (i) Initialisierung von Daten ACCOUNT, PHASE
 * (ii) Eingabe spezieller Werte in ACCOUNT, PHASE
 * (iii) Berechnung des Nachfolgers
 *       Ausgabe Status
 * (v) Evtl Korrektur von Werten
 * (vi) Abbruch oder Wiederholung
 *
 * compilation: gcc -o esim5 esim5.c esim5_source3.c
 * usage: esim5
 *
 **************************************************/

#include <stdio.h>
#include "esim5.h"

int main(void){

  int i,year;
  float birth;

  /*********************************
   *
   * (i) INITIALISIERUNG VON DATEN
   *
   ***********************************************/


  struct SIMULATION sim = {COUNTRY_PHASE_NUMBER,1,0,0,0};

  /************************************************
   *
  *  EINRICHTEN VON KONTEN MIT DEFINIERTEM ANFANGSWERT (INITIALISIERUNG)
  *
  *****************************************************************************************************/

  struct ACCOUNT RK = {0.0, 0.0, 0.0, 1000000.0, "Euro"};
  struct ACCOUNT XRA, AK, KK, AG;


 /******  EINRICHTEN VON PHASEN  *****/


struct PHASE germany[COUNTRY_PHASE_NUMBER];


/******* INITIALISIERUNG DER RESTLICHEN KONTEN DURCH WERTZUWEISUNG ******/

  XRA = RK;
  AK = RK;
  KK = RK;
  AG = RK;

  /********* INITIALISIERUNG DER PHASEN DURCH INITIALISIERUNGSFUNKTION *********/

 for( i=0; i<COUNTRY_PHASE_NUMBER; i++) init_data_phase(&germany[i],i);

 /*********************************************************
  *
 *  (ii.a) Eingabe spezieller Werte fuer max_phase und sim_duration
 *
 **********************************************************/

printf("***** BEGINN EINGABE VON STARTWERTEN  ***** \n");


input_data_general(&sim);

 if (sim.max_phase >= 2) { sim.birth_low = 2; }

 if(sim.max_phase >=4) {sim.birth_high = 4; }
 else {sim.birth_high = sim.max_phase; }


 /*********************************************************
  *
 *  (ii.b) Eingabe spezieller Werte in ACCOUNT, PHASE
 *
 **********************************************************
*
* BEGINN DATENEINGABE SPEZIELLER STARTWERTE FUER KONTEN
*
*********************************************************************************************/



input_data_account(&RK, "RK");
input_data_account(&AG, "AG");

/*******************
input_data_account(&XRA, "XRA");
input_data_account(&AK, "AK");
input_data_account(&KK, "KK");
***********/

/*********** BEGINN DATENEINGABE SPEZIELLER STARTWERTE FUER PHASE *************************/


 for( i=0; i<sim.max_phase; i++) {
                 input_data_phase_demographic(&germany[i],i);
                 input_data_phase_pension(&germany[i],i);
 }


 /************************************
  *
  * (iii) Berechnung des Nachfolgers
  *
  ******************************************/

 year = 0;


 while( year < sim.sim_duration){


 compute_phase_shift(&germany[0], &sim);

 printf("\n");
 compute_phase_flow(&germany[0],sim.max_phase);


  printf("\n");
 RK.in += 2* compute_rk_in(&germany[0],sim.max_phase); /* AG zahlen nochmals den gleichen Betrag in die RK
							* wie Beschäftigte */
AG.out += compute_rk_in(&germany[0],sim.max_phase);

 printf("\n");
 RK.out += compute_rk_out(&germany[0],sim.max_phase,&sim );

 printf("\n");
 RK.sum = RK.in - RK.out;
 AG.sum = AG.in - AG.out;

/*********** AUSGABE AKTUELLER STATUS ***************************************/

printf("***** BEGINN AUSGABE AKTUELLE STATUSWERTE ***** \n\n");

printf("YEAR = %d --- POP = %.2f --- RK.in = %.2f --- RK.out = %.2f \n",year, compute_pop_number(&germany[0],sim.max_phase),2* compute_rk_in(&germany[0],sim.max_phase), compute_rk_in(&germany[0],sim.max_phase));
 output_data_account(&RK, "RK");
 output_data_account(&AG, "AG");

/* for( i=0; i<sim.max_phase; i++) output_data_phase_head(&germany[i],i); */


/*******************+
output_data_account(&AG, "AG");
output_data_account(&XRA, "XRA");
output_data_account(&AK, "AK");
output_data_account(&KK, "KK");
 **************/

 year++;

 }/*End of while computation */

 return (1);
}



/************************************
 *
 * esim5_source3.c
 *
 * author: gdh
 * first: dec-10,02
 * last: jan-6, 03
 * idea: Hilfsfunktionen fuer esim5.c
 *
 *
* int input_data_general(struct SIMULATION *);
* int input_data_account(struct ACCOUNT *, char *s);
* int output_data_account(struct ACCOUNT *, char *s);
* int init_data_phase_demographic(struct PHASE *,int);
* int input_data_phase_pension(struct PHASE *,int);
* int input_data_phase(struct PHASE *,int);
* int output_data_phase_head(struct PHASE *,int);
* int output_data_phase(struct PHASE *,int);
*  float compute_birth(struct PHASE *,  struct SIMULATION *);
* int compute_phase_shift(struct PHASE *,  struct SIMULATION *);
* int compute_phase_flow(struct PHASE *, int);
* float compute_pop_number(struct PHASE *,  int);
* float compute_rk_in(struct PHASE *php,  int phase_max);
* float compute_rk_out(struct PHASE *php,  int phase_max, struct SIMULATION *simp);
 **************************************************/

#include <stdio.h>
#include <stdlib.h>   /* Fuer Konvertierungsfunktionen atoi, atof ... */
#include "esim5.h"

#define INPUT_LENGTH 50 /* Input_data_phase() input-string */


/********************************
 *
 * input_data_general()
 *
 * idea: Eingabe allgemeiner Werte fuer Simulation
 *
 ************************************/


int input_data_general(struct SIMULATION *simp){


  char input[50];

  printf("\n\n********* BEGINN EINGABE ALLGEMEINER STARTWERTE  *******************\n\n");

  printf("\nGENERAL:  Anzahl Phasen (int) (MAXIMUM = %d)\n: ", simp->max_phase);

  fgets(input,INPUT_LENGTH-1,stdin);

     simp->max_phase = atoi(input);

  printf("PHASE:  Max.Anzahl Phasen = %d\n",simp->max_phase);

  /**********************************************************************************/

  printf("\nGENERAL:  Anzahl Durchgaenge/ Jahre (int)\n: ");

  fgets(input,INPUT_LENGTH-1,stdin);

     simp->sim_duration = atoi(input);

  printf("PHASE:  Anzahl Durchgaenge/Jahre = %d\n",simp->sim_duration);

  /**********************************************************************************/

  printf("\nGENERAL: Beginn der Pensionierung1 (Phase)\n: ");

  fgets(input,INPUT_LENGTH-1,stdin);

     simp->retirement_begin = atoi(input);

  printf("PHASE:  Beginn der Pensionierung1  = %d\n",simp->retirement_begin);

  /**********************************************************************************/


  return(1);
}

int input_data_account(struct ACCOUNT *accp, char *string){

  printf("\nSTARTWERT fuer %s : ",string);
  scanf("%f",&accp->sum);
  getchar();

  return(1);
}

int output_data_account(struct ACCOUNT *accp, char *string){

  printf("\nAKTUELLER STATUS von %s IN = %.2f , OUT = %.2f,  SUMME = %.2f\n",string,accp->in, accp->out, accp->sum);

  return(1);
}

int init_data_phase(struct PHASE *php,int phase_number){

  if(phase_number < 1) {

  php->interval[0] = 0;
  php->interval[1] = 5;
  printf("Kontrolle : Phasezahlen %d - %d \n", php->interval[0], php->interval[1]);
  }
  else {
  php->interval[0] =((phase_number-1) * 10) +6;
  php->interval[1] =((phase_number-1) * 10) +15;

  printf("Kontrolle : Phasezahlen %d - %d \n", php->interval[0], php->interval[1]);
  }

  php->number = 0.0;
  php->percentage_men = 0.0;
  php->percentage_women = 0.0;
  php->birthrate = 0.0;
  php->deathrate = 0.0;
  php->migration_plus = 0.0;
  php->migration_minus = 0.0;

  php->self_employed.percentage_of_number = 0.0;
php->self_employed.actual_yearly_income = 0.0;
php->self_employed.last_yearly_income = 0.0;
php->self_employed.former_yearly_income = 0.0;
php->self_employed.RK_payment_percentage = 0.0;
php->self_employed.RK_income_percentage = 0.0;
php->self_employed.AK_payment_percentage = 0.0;
php->self_employed.AK_income_percentage = 0.0;
php->self_employed.KK_payment_percentage = 0.0;
php->self_employed.KK_income_percentage = 0.0;
php->self_employed.XRA_payment_percentage  = 0.0;
php->self_employed.XRA_income_percentage = 0.0;
php->self_employed.AG_payment = 0.0;
php->self_employed.AG_income = 0.0;

 php->employed.percentage_of_number = 0.0;
php->employed.actual_yearly_income = 0.0;
php->employed.last_yearly_income = 0.0;
php->employed.former_yearly_income = 0.0;
php->employed.RK_payment_percentage = 0.0;
php->employed.RK_income_percentage = 0.0;
php->employed.AK_payment_percentage = 0.0;
php->employed.AK_income_percentage = 0.0;
php->employed.KK_payment_percentage = 0.0;
php->employed.KK_income_percentage = 0.0;
php->employed.XRA_payment_percentage = 0.0;
php->employed.XRA_income_percentage = 0.0;
php->employed.AG_payment = 0.0;
php->employed.AG_income = 0.0;

 php->unemployed.percentage_of_number = 0.0;
php->unemployed.actual_yearly_income = 0.0;
php->unemployed.last_yearly_income = 0.0;
php->unemployed.former_yearly_income = 0.0;
php->unemployed.RK_payment_percentage = 0.0;
php->unemployed.RK_income_percentage = 0.0;
php->unemployed.AK_payment_percentage = 0.0;
php->unemployed.AK_income_percentage = 0.0;
php->unemployed.KK_payment_percentage = 0.0;
php->unemployed.KK_income_percentage = 0.0;
php->unemployed.XRA_payment_percentage = 0.0;
php->unemployed.XRA_income_percentage = 0.0;
php->unemployed.AG_payment = 0.0;
php->unemployed.AG_income = 0.0;

 php->education.percentage_of_number = 0.0;
 php->education.actual_yearly_income = 0.0;
php->education.last_yearly_income = 0.0;
php->education.former_yearly_income = 0.0;
php->education.RK_payment_percentage = 0.0;
php->education.RK_income_percentage = 0.0;
php->education.AK_payment_percentage = 0.0;
php->education.AK_income_percentage = 0.0;
php->education.KK_payment_percentage = 0.0;
php->education.KK_income_percentage = 0.0;
php->education.XRA_payment_percentage = 0.0;
php->education.XRA_income_percentage = 0.0;
php->education.AG_payment = 0.0;
php->education.AG_income = 0.0;

 php->retired_persons1.percentage_of_number = 0.0;
 php->retired_persons1.actual_yearly_income = 0.0;
php->retired_persons1.last_yearly_income = 0.0;
php->retired_persons1.former_yearly_income = 0.0;
php->retired_persons1.RK_payment_percentage = 0.0;
php->retired_persons1.RK_income_percentage = 0.0;
php->retired_persons1.AK_payment_percentage = 0.0;
php->retired_persons1.AK_income_percentage = 0.0;
php->retired_persons1.KK_payment_percentage = 0.0;
php->retired_persons1.KK_income_percentage = 0.0;
php->retired_persons1.XRA_payment_percentage = 0.0;
php->retired_persons1.XRA_income_percentage = 0.0;
php->retired_persons1.AG_payment = 0.0;
php->retired_persons1.AG_income = 0.0;

 php->retired_persons2.percentage_of_number = 0.0;
php->retired_persons2.actual_yearly_income = 0.0;
php->retired_persons2.last_yearly_income = 0.0;
php->retired_persons2.former_yearly_income = 0.0;
php->retired_persons2.RK_payment_percentage = 0.0;
php->retired_persons2.RK_income_percentage = 0.0;
php->retired_persons2.AK_payment_percentage = 0.0;
php->retired_persons2.AK_income_percentage = 0.0;
php->retired_persons2.KK_payment_percentage = 0.0;
php->retired_persons2.KK_income_percentage = 0.0;
php->retired_persons2.XRA_payment_percentage = 0.0;
php->retired_persons2.XRA_income_percentage = 0.0;
php->retired_persons2.AG_payment = 0.0;
php->retired_persons2.AG_income = 0.0;

 php->sick_persons.percentage_of_number = 0.0;
php->sick_persons.actual_yearly_income = 0.0;
php->sick_persons.last_yearly_income = 0.0;
php->sick_persons.former_yearly_income = 0.0;
php->sick_persons.RK_payment_percentage = 0.0;
php->sick_persons.RK_income_percentage= 0.0;
php->sick_persons.AK_payment_percentage = 0.0;
php->sick_persons.AK_income_percentage= 0.0;
php->sick_persons.KK_payment_percentage = 0.0;
php->sick_persons.KK_income_percentage= 0.0;
php->sick_persons.XRA_payment_percentage = 0.0;
php->sick_persons.XRA_income_percentage= 0.0;
php->sick_persons.AG_payment = 0.0;
php->sick_persons.AG_income = 0.0;



  return(1);
}

/********************************
 *
 * input_data_phase_demographic()
 *
 * idea: Eingabe spezieller demographischer Werte fuer einzelne Phasen
 *
 ************************************/


int input_data_phase_demographic(struct PHASE *php,int phase_number){

  char input[50];

  printf("\n\n********* BEGINN EINGABE SPEZIELLER STARTWERTE FUER PHASE  *******************\n\n");
  printf("Phasezahlen %d - %d \n", php->interval[0], php->interval[1]);

  printf("\n\n*****************************************************************************\n\n");
  printf("PHASE:  Anzahl Mitglieder (Vorher) = %.2f\n",php->number);

  printf("\nPHASE: Anzahl Mitglieder  = ");

  fgets(input,INPUT_LENGTH-1,stdin);

     php->number = atof(input);

  printf("PHASE:  Anzahl Mitglieder Neu = %.2f\n",php->number);

  /**********************************************************************************/

  printf("\nPHASE: Proz-Maenner Vorher (Gleitkomma) = %.2f", php->percentage_men);
  printf("\nPHASE: Proz-Maenner (Gleitkomma) = ");


  fgets(input,INPUT_LENGTH-1,stdin);
     php->percentage_men = atof(input);

  printf("PHASE:  Proz-Maenner Neu = %.2f\n",php->percentage_men);


  php->percentage_women = 100.0 - php->percentage_men;
  printf("PHASE:  Proz-Frauen Neu = %.2f\n",php->percentage_women);



  /**********************************************************************************/

  printf("\nPHASE: Geburtenrate (Gleitkomma) = %.2f ",php->birthrate);
  printf("\nPHASE: Geburtenrate (Gleitkomma) = ");
 fgets(input,INPUT_LENGTH-1,stdin);
  php->birthrate = atof(input);
  printf("PHASE:  Geburtenrate Neu = %.2f\n",php->birthrate);



  /**********************************************************************************/

  printf("\nPHASE: Sterberate (Gleitkomma) = %.2f ",php->deathrate);
  printf("\nPHASE: Sterberate (Gleitkomma) = ");
 fgets(input,INPUT_LENGTH-1,stdin);
  php->deathrate = atof(input);
  printf("PHASE:  Sterberate Neu = %.2f\n",php->deathrate);



  /**********************************************************************************/

  printf("\nPHASE: Zuwanderung (Gleitkomma) = %.2f ",php->migration_plus);
  printf("\nPHASE: Zuwanderung (Gleitkomma) = ");
 fgets(input,INPUT_LENGTH-1,stdin);
  php->migration_plus = atof(input);
  printf("PHASE: Zuwanderung  Neu = %.2f\n",php->migration_plus);


  /**********************************************************************************/

  printf("\nPHASE: Abwanderung (Gleitkomma) = %.2f ",php->migration_minus);
  printf("\nPHASE: Abwanderung (Gleitkomma) = ");
 fgets(input,INPUT_LENGTH-1,stdin);
  php->migration_minus = atof(input);
  printf("PHASE: Abwanderung  Neu = %.2f\n",php->migration_minus);


  /**********************************************************************************/

  return(1);
}

/********************************
 *
 * input_data_phase_pension()
 *
 * idea: Eingabe spezieller Renten1-Werte fuer einzelne Phasen
 *
 ************************************/


int input_data_phase_pension(struct PHASE *php,int phase_number){

  char input[50];

  printf("\n\n********* BEGINN EINGABE SPEZIELLER RENTEN-STARTWERTE FUER PHASE  *******************\n\n");
  printf("Phasezahlen %d - %d \n", php->interval[0], php->interval[1]);

  printf("\n\n*****************************************************************************\n\n");
  printf("PHASE: Proz-Anteil Beschaeftigter  (Vorher) = %.2f\n",php->employed.percentage_of_number);

  printf("\nPHASE: Proz-Anteil Beschaeftigter  = ");

  fgets(input,INPUT_LENGTH-1,stdin);

     php->employed.percentage_of_number = atof(input);

  printf("PHASE:  Proz-Anteil Beschaeftigter Neu  = %.2f\n",php->employed.percentage_of_number);

  /**********************************************************************************/

  printf("\nPHASE: Jaehrl. Bruttoeinkommen bisher (Gleitkomma) = %.2f", php->employed.actual_yearly_income);
  printf("\nPHASE:  Jaehrl. Bruttoeinkommen (Gleitkomma) = ");


  fgets(input,INPUT_LENGTH-1,stdin);
     php->employed.actual_yearly_income = atof(input);

  printf("PHASE:  Jaehrl. Bruttoeinkommen  Neu = %.2f\n",php->employed.actual_yearly_income);

  /**********************************************************************************/

  printf("\nPHASE: Proz-Anteil RK-Zahlung bisher (Gleitkomma) = %.2f", php->employed.RK_payment_percentage);
  printf("\nPHASE:   Proz-Anteil RK-Zahlung (Gleitkomma) = ");


  fgets(input,INPUT_LENGTH-1,stdin);
     php->employed.RK_payment_percentage  = atof(input);

  printf("PHASE:  Proz-Anteil RK-Zahlung   Neu = %.2f\n",  php->employed.RK_payment_percentage);




  /**********************************************************************************/



  printf("\nPHASE: Proz-Anteil RK-Einkommen bisher (Gleitkomma) = %.2f", php->retired_persons1.RK_income_percentage);
  printf("\nPHASE:   Proz-Anteil RK-Einkommen (Gleitkomma) = ");


  fgets(input,INPUT_LENGTH-1,stdin);
     php->retired_persons1.RK_income_percentage  = atof(input);

  printf("PHASE:  Proz-Anteil RK-Einkommen  Neu = %.2f\n",  php->retired_persons1.RK_income_percentage);



  /**********************************************************************************
   *
   * Der Anteil der Rentner1 sowie ihr vormaliges Einkommen werden automatisch auf der Basis der Zahlen
   * der zuletzt Beschäftigten errechnet.
   * Dazu benötigt man den globalen Parameter aus der Struktur SIMULATION 'retirment_begin'
   *
   ***********************************************************************************/


  return(1);
}


int output_data_phase_head(struct PHASE *php,int phase_number){

  printf("\n\n********* PHASE ZAHLEN *******************\n\n");
  printf("Phasezahlen %d - %d \n", php->interval[0], php->interval[1]);

  printf("\n***********************************************\n\n");

  printf("PHASE number = %.2f \n", php->number);
  printf("PHASE percentage_men = %.2f \n", php->percentage_men );
  printf("PHASE percentage_women  = %.2f \n",php->percentage_women );
  printf("PHASE birthrate  = %.2f \n",php->birthrate );
   printf("PHASE deathrate  = %.2f \n",php->deathrate);
   printf("PHASE migration_plus  = %.2f \n",php->migration_plus);
   printf("PHASE migration_minus  = %.2f \n",php->migration_minus);

   return(1);
}


int output_data_phase(struct PHASE *php,int phase_number){

  printf("\n\n********* PHASE ZAHLEN *******************\n\n");
  printf("Phasezahlen %d - %d \n", php->interval[0], php->interval[1]);

  printf("\n**********************************************\n\n");

  printf("PHASE number = %.2f \n", php->number);
  printf("PHASE percentage_men = %.2f \n", php->percentage_men );
  printf("PHASE percentage_women  = %.2f \n",php->percentage_women );
  printf("PHASE birthrate  = %.2f \n",php->birthrate );
   printf("PHASE deathrate  = %.2f \n",php->deathrate);
   printf("PHASE migration_plus  = %.2f \n",php->migration_plus);
   printf("PHASE migration_minus  = %.2f \n",php->migration_minus);

  printf("PHASE self_employed.percentage_of_number  = %.2f \n", php->self_employed.percentage_of_number );
printf("PHASE self_employed.actual_yearly_income  = %.2f \n", php->self_employed.actual_yearly_income );
printf("PHASE self_employed.last_yearly_income  = %.2f \n", php->self_employed.last_yearly_income );
printf("PHASE self_employed.former_yearly_income  = %.2f \n", php->self_employed.former_yearly_income );
printf("PHASE self_employed.RK_payment_percentage  = %.2f \n", php->self_employed.RK_payment_percentage );
printf("PHASE self_employed.RK_income_percentage = %.2f \n", php->self_employed.RK_income_percentage);
printf("PHASE self_employed.AK_payment_percentage  = %.2f \n", php->self_employed.AK_payment_percentage );
printf("PHASE self_employed.AK_income_percentage = %.2f \n", php->self_employed.AK_income_percentage);
printf("PHASE self_employed.KK_payment_percentage  = %.2f \n", php->self_employed.KK_payment_percentage );
printf("PHASE self_employed.KK_income_percentage = %.2f \n", php->self_employed.KK_income_percentage);
printf("PHASE self_employed.XRA_payment_percentage   = %.2f \n", php->self_employed.XRA_payment_percentage );
printf("PHASE self_employed.XRA_income_percentage = %.2f \n", php->self_employed.XRA_income_percentage);
printf("PHASE self_employed.AG_payment  = %.2f \n", php->self_employed.AG_payment );
printf("PHASE self_employed.AG_income = %.2f \n", php->self_employed.AG_income);

printf("PHASE employed.actual_yearly_income  = %.2f \n", php->employed.actual_yearly_income );
printf("PHASE employed.last_yearly_income  = %.2f \n", php->employed.last_yearly_income );
printf("PHASE employed.former_yearly_income  = %.2f \n", php->employed.former_yearly_income );
printf("PHASE employed.RK_payment_percentage  = %.2f \n", php->employed.RK_payment_percentage );
printf("PHASE employed.RK_income_percentage = %.2f \n", php->employed.RK_income_percentage);
printf("PHASE employed.AK_payment_percentage  = %.2f \n", php->employed.AK_payment_percentage );
printf("PHASE employed.AK_income_percentage = %.2f \n", php->employed.AK_income_percentage);
printf("PHASE employed.KK_payment_percentage  = %.2f \n", php->employed.KK_payment_percentage );
printf("PHASE employed.KK_income_percentage = %.2f \n", php->employed.KK_income_percentage);
printf("PHASE employed.XRA_payment_percentage   = %.2f \n", php->employed.XRA_payment_percentage );
printf("PHASE employed.XRA_income_percentage = %.2f \n", php->employed.XRA_income_percentage);
printf("PHASE employed.AG_payment  = %.2f \n", php->employed.AG_payment );
printf("PHASE employed.AG_income = %.2f \n", php->employed.AG_income);

printf("PHASE unemployed.actual_yearly_income  = %.2f \n", php->unemployed.actual_yearly_income );
printf("PHASE unemployed.last_yearly_income  = %.2f \n", php->unemployed.last_yearly_income );
printf("PHASE unemployed.former_yearly_income  = %.2f \n", php->unemployed.former_yearly_income );
printf("PHASE unemployed.RK_payment_percentage  = %.2f \n", php->unemployed.RK_payment_percentage );
printf("PHASE unemployed.RK_income_percentage = %.2f \n", php->unemployed.RK_income_percentage);
printf("PHASE unemployed.AK_payment_percentage  = %.2f \n", php->unemployed.AK_payment_percentage );
printf("PHASE unemployed.AK_income_percentage = %.2f \n", php->unemployed.AK_income_percentage);
printf("PHASE unemployed.KK_payment_percentage  = %.2f \n", php->unemployed.KK_payment_percentage );
printf("PHASE unemployed.KK_income_percentage = %.2f \n", php->unemployed.KK_income_percentage);
printf("PHASE unemployed.XRA_payment_percentage   = %.2f \n", php->unemployed.XRA_payment_percentage );
printf("PHASE unemployed.XRA_income_percentage = %.2f \n", php->unemployed.XRA_income_percentage);
printf("PHASE unemployed.AG_payment  = %.2f \n", php->unemployed.AG_payment );
printf("PHASE unemployed.AG_income = %.2f \n", php->unemployed.AG_income);

printf("PHASE education.actual_yearly_income  = %.2f \n", php->education.actual_yearly_income );
printf("PHASE education.last_yearly_income  = %.2f \n", php->education.last_yearly_income );
printf("PHASE education.former_yearly_income  = %.2f \n", php->education.former_yearly_income );
printf("PHASE education.RK_payment_percentage  = %.2f \n", php->education.RK_payment_percentage );
printf("PHASE education.RK_income_percentage = %.2f \n", php->education.RK_income_percentage);
printf("PHASE education.AK_payment_percentage  = %.2f \n", php->education.AK_payment_percentage );
printf("PHASE education.AK_income_percentage = %.2f \n", php->education.AK_income_percentage);
printf("PHASE education.KK_payment_percentage  = %.2f \n", php->education.KK_payment_percentage );
printf("PHASE education.KK_income_percentage = %.2f \n", php->education.KK_income_percentage);
printf("PHASE education.XRA_payment_percentage   = %.2f \n", php->education.XRA_payment_percentage );
printf("PHASE education.XRA_income_percentage = %.2f \n", php->education.XRA_income_percentage);
printf("PHASE education.AG_payment  = %.2f \n", php->education.AG_payment );
printf("PHASE education.AG_income = %.2f \n", php->education.AG_income);

printf("PHASE retired_persons1.actual_yearly_income  = %.2f \n", php->retired_persons1.actual_yearly_income );
printf("PHASE retired_persons1.last_yearly_income  = %.2f \n", php->retired_persons1.last_yearly_income );
printf("PHASE retired_persons1.former_yearly_income  = %.2f \n", php->retired_persons1.former_yearly_income );
printf("PHASE retired_persons1.RK_payment_percentage  = %.2f \n", php->retired_persons1.RK_payment_percentage );
printf("PHASE retired_persons1.RK_income_percentage = %.2f \n", php->retired_persons1.RK_income_percentage);
printf("PHASE retired_persons1.AK_payment_percentage  = %.2f \n", php->retired_persons1.AK_payment_percentage );
printf("PHASE retired_persons1.AK_income_percentage = %.2f \n", php->retired_persons1.AK_income_percentage);
printf("PHASE retired_persons1.KK_payment_percentage  = %.2f \n", php->retired_persons1.KK_payment_percentage );
printf("PHASE retired_persons1.KK_income_percentage = %.2f \n", php->retired_persons1.KK_income_percentage);
printf("PHASE retired_persons1.XRA_payment_percentage   = %.2f \n", php->retired_persons1.XRA_payment_percentage );
printf("PHASE retired_persons1.XRA_income_percentage = %.2f \n", php->retired_persons1.XRA_income_percentage);
printf("PHASE retired_persons1.AG_payment  = %.2f \n", php->retired_persons1.AG_payment );
printf("PHASE retired_persons1.AG_income = %.2f \n", php->retired_persons1.AG_income);


printf("PHASE retired_persons2.actual_yearly_income  = %.2f \n", php->retired_persons2.actual_yearly_income );
printf("PHASE retired_persons2.last_yearly_income  = %.2f \n", php->retired_persons2.last_yearly_income );
printf("PHASE retired_persons2.former_yearly_income  = %.2f \n", php->retired_persons2.former_yearly_income );
printf("PHASE retired_persons2.RK_payment_percentage  = %.2f \n", php->retired_persons2.RK_payment_percentage );
printf("PHASE retired_persons2.RK_income_percentage = %.2f \n", php->retired_persons2.RK_income_percentage);
printf("PHASE retired_persons2.AK_payment_percentage  = %.2f \n", php->retired_persons2.AK_payment_percentage );
printf("PHASE retired_persons2.AK_income_percentage = %.2f \n", php->retired_persons2.AK_income_percentage);
printf("PHASE retired_persons2.KK_payment_percentage  = %.2f \n", php->retired_persons2.KK_payment_percentage );
printf("PHASE retired_persons2.KK_income_percentage = %.2f \n", php->retired_persons2.KK_income_percentage);
printf("PHASE retired_persons2.XRA_payment_percentage   = %.2f \n", php->retired_persons2.XRA_payment_percentage );
printf("PHASE retired_persons2.XRA_income_percentage = %.2f \n", php->retired_persons2.XRA_income_percentage);
printf("PHASE retired_persons2.AG_payment  = %.2f \n", php->retired_persons2.AG_payment );
printf("PHASE retired_persons2.AG_income = %.2f \n", php->retired_persons2.AG_income);


printf("PHASE sick_persons.actual_yearly_income  = %.2f \n", php->sick_persons.actual_yearly_income );
printf("PHASE sick_persons.last_yearly_income  = %.2f \n", php->sick_persons.last_yearly_income );
printf("PHASE sick_persons.former_yearly_income  = %.2f \n", php->sick_persons.former_yearly_income );
printf("PHASE sick_persons.RK_payment_percentage  = %.2f \n", php->sick_persons.RK_payment_percentage );
printf("PHASE sick_persons.RK_income_percentage = %.2f \n", php->sick_persons.RK_income_percentage);
printf("PHASE sick_persons.AK_payment_percentage  = %.2f \n", php->sick_persons.AK_payment_percentage );
printf("PHASE sick_persons.AK_income_percentage = %.2f \n", php->sick_persons.AK_income_percentage);
printf("PHASE sick_persons.KK_payment_percentage  = %.2f \n", php->sick_persons.KK_payment_percentage );
printf("PHASE sick_persons.KK_income_percentage = %.2f \n", php->sick_persons.KK_income_percentage);
printf("PHASE sick_persons.XRA_payment_percentage   = %.2f \n", php->sick_persons.XRA_payment_percentage );
printf("PHASE sick_persons.XRA_income_percentage = %.2f \n", php->sick_persons.XRA_income_percentage);
printf("PHASE sick_persons.AG_payment  = %.2f \n", php->sick_persons.AG_payment );
printf("PHASE sick_persons.AG_income  = %.2f \n", php->sick_persons.AG_income);


  return(1);
}

/***************************
 *
 * compute_birth()
 *
 * idea: Berechnet in Abhaengigkeit von Phase, Anzahl, Proz.Frauen,
 *           Geburtenrate die Anzahl der Geburten insgesamt pro Jahr
 *
 ********************************************/

float compute_birth(struct PHASE *php, struct SIMULATION *simp){

  /* Es wird angenommen, dass als Adresse Phase[0] uebergeben wird. Die Phasen mit den
   * geburtsfaehigen Frauen werden mittels den Parametern 'low' und 'high' als
   * Offset zu Phase[0] berechnet
   */

   float birth_sum = 0;
   int i;

   for(i = simp->birth_low; i < simp->birth_high+1; i++){
     birth_sum +=  (php[i].number * (php[i].percentage_women/100.0) * php[i].birthrate);
   }

   return birth_sum;

}
/***************************
 *
 * compute_phase_shift()
 *
 * idea: Berechnet die Verschiebung der Populationen zwischen den
 *       Phasen, beginnend bei der hoechsten Phase
 *
 ********************************************/

int compute_phase_shift(struct PHASE *php,  struct SIMULATION *simp) {

  /* Es wird angenommen, dass als Adresse Phase[0] uebergeben wird. Andere Phasen
   * werden als Offset zu Phase[0] berechnet
   */

   int i;
   float birth;


 birth = compute_birth(php, simp);
 printf("GEBURTEN = %f\n",birth);

   i=simp->max_phase-1;

   /* Die oberste Phase gibt keine Anteile weiter, sonder bekommt nur Anteile von der unteren Phase */

     /* printf("TEST compute_phase_shift BEFORE %d = %f\n",i,php[i].number); */
     php[i].number += php[i-1].number/((php[i-1].interval[1] - php[i-1].interval[0])+1.0);
     /* printf("TEST compute_phase_shift AFTER %d = %f\n",i,php[i].number); */

     i--;

     while(i>0) {
     /* printf("TEST compute_phase_shift BEFORE %d = %f\n",i,php[i].number); */
     php[i].number =  php[i].number - (php[i].number/((php[i].interval[1] - php[i].interval[0])+1.0)) +  (php[i-1].number/((php[i-1].interval[1] - php[i-1].interval[0])+1.0 ) ) ;
    /*  printf("TEST compute_phase_shift AFTER %d = %f\n",i,php[i].number); */
     i--;

   }/*End of while */

     /* Die unterste Phase gib Anteile weiter und bekommt Geburten */

   /* printf("TEST compute_phase_shift BEFORE %d = %f\n",i,php[i].number); */

     php[i].number =  php[i].number - ( php[i].number/( (php[i].interval[1] - php[i].interval[0])+1.0 ) ) + birth;

     /*  printf("TEST compute_phase_shift AFTER %d = %f\n",i,php[i].number); */


   return (1);
}
/***************************
 *
 * compute_phase_flow()
 *
 * idea: Berechnet die Verschiebung der Populationen durch
 *       Migration und Sterbefaelle
 *
 ********************************************/

int compute_phase_flow(struct PHASE *php, int phase_max) {

  /* Es wird angenommen, dass als Adresse Phase[0] uebergeben wird. Andere Phasen
   * werden als Offset zu Phase[0] berechnet
   */

   int i;

   for(i=0; i<phase_max; i++) {
     /*  printf("TEST compute_phase_flow BEFORE %d = %f\n",i,php[i].number); */

     php[i].number += (php[i].migration_plus - php[i].migration_minus - ( php[i].number * php[i].deathrate));

     /*  printf("TEST compute_phase_flow AFTER %d = %f\n",i,php[i].number); */

   }/*End of for */

   return (1);
}

/***************************
 *
 * compute_pop_number()
 *
 * idea: Berechnet die Gesamtpopulation
 *
 ********************************************/

float compute_pop_number(struct PHASE *php,  int phase_max) {

  /* Es wird angenommen, dass als Adresse Phase[0] uebergeben wird. Andere Phasen
   * werden als Offset zu Phase[0] berechnet
   */

   int i;
   float pop_number=0;

   for(i=0; i<phase_max; i++) {
     pop_number += php[i].number;

   }/*End of for */

    /* printf("TEST compute_pop_number  %f\n",pop_number); */

   return (pop_number);
}

/***************************
 *
 * compute_rk_in()
 *
 * idea: Berechnet den Mittelzufluss zu RK
 *
 *
 * RK.in += number * employed.percentage_of_number * employed.RK_payment_percentage * employed.actual_yearly_income

 ********************************************/

float compute_rk_in(struct PHASE *php,  int phase_max) {

  /* Es wird angenommen, dass als Adresse Phase[0] uebergeben wird. Andere Phasen
   * werden als Offset zu Phase[0] berechnet.
   */

   int i;
   float rk_new_amount =0;

   for(i=0; i<phase_max; i++) {
     rk_new_amount  += php[i].number * (php[i].employed.percentage_of_number/100) * (php[i].employed.RK_payment_percentage/100) * php[i].employed.actual_yearly_income;


   }/*End of for */


   return ( rk_new_amount);
}
/***************************
 *
 * compute_rk_out()
 *
 * idea: Berechnet den Mittelabfluss von RK
 *
 *
 * RK.out -= number * retired_persons1.percentage_of_number  * retired_persons1.RK_payment_percentage *
 *  retired_persons1.former_yearly_income</p>
 *
 ********************************************/

float compute_rk_out(struct PHASE *php,  int phase_max, struct SIMULATION *simp) {

  /* Es wird angenommen, dass als Adresse Phase[0] uebergeben wird. Andere Phasen
   * werden als Offset zu Phase[0] berechnet. In SIMULATION befindet sich der Beginn der Rentenzahlung
   * Das letzte Einkommen wird berechnet nach dem aktuellen Einkommen der letzten Phase vor der Rente1
   * Die Rate der Rentner wird berechnet nach der Rate der Beschäftigten vor der Rente
   */

   int i;


   float former_income = php[simp->retirement_begin-1].employed.actual_yearly_income;
   float retired1_percentage =  php[simp->retirement_begin-1].employed.percentage_of_number;
   float rk_out_amount =0;


   for(i=simp->retirement_begin; i<phase_max; i++) {

     rk_out_amount  += php[i].number * ( retired1_percentage/100) * (php[i].retired_persons1.RK_income_percentage/100) *  former_income;

   }/*End of for */


   return ( rk_out_amount);
}

START

5. Grafische Ausgabe


START

6. Einlesen über eine Datei


START

7. Übungsaufgaben

In den Übungen


START