-
Notifications
You must be signed in to change notification settings - Fork 1
/
jpoffice_functions_top.c
174 lines (154 loc) · 5.91 KB
/
jpoffice_functions_top.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "header.h"
#include "jpoffice_agent_header.h"
#include "./library_header.h"
/*
* \fn: int jpoffice_init_employment()
* \brief:
*/
int jpoffice_init_employment()
{
/* Initialize */
/* Allocate firms and household arrays. */
int_array household_list;
int_array regular_firm_list;
int_array constructor_firm_list;
int firm_type, firm_id, household_id;
int nhouseholds, nrfirms, ncfirms;
int constructor_firm_size, employment_size;
int nemployed = 0;
int i,j;
/* initialize arrays */
init_int_array(&household_list);
init_int_array(®ular_firm_list);
init_int_array(&constructor_firm_list);
/* Collect household IDs */
START_HOUSEHOLD_JPOFFICE_ID_MESSAGE_LOOP
household_id = household_jpoffice_id_message->household_id;
add_int(&household_list, household_id);
FINISH_HOUSEHOLD_JPOFFICE_ID_MESSAGE_LOOP
nhouseholds = household_list.size;
if (nhouseholds == 0 ) {
if (WARNING_MODE) {
printf("Warning @jpoffice_init_employment(): No household is detected at initiliazation.\n");
}
free_int_array(&household_list);
free_int_array(®ular_firm_list);
free_int_array(&constructor_firm_list);
return 0;
}
/* Collect firm IDs */
START_FIRM_JPOFFICE_ID_MESSAGE_LOOP
firm_id = firm_jpoffice_id_message->firm_id;
firm_type = firm_jpoffice_id_message->isconstructor;
if (firm_type == 0) {
add_int(®ular_firm_list, firm_id);
} else {
add_int(&constructor_firm_list, firm_id);
}
FINISH_FIRM_JPOFFICE_ID_MESSAGE_LOOP
nrfirms = regular_firm_list.size;
ncfirms = constructor_firm_list.size;
/* employment ratio is 0.9
* number of employees at construction sector is 7.5% of population.
* These 2 values should be added to jpoffice memory for parameterization!!
*/
constructor_firm_size = (int) (nhouseholds * 0.075 / ncfirms);
employment_size = (int) (nhouseholds * 0.90);
if (PRINT_DEBUG_MODE) {
printf("nRFirms: %d nCFirms: %d, nHH: %d\n", nrfirms, ncfirms, nhouseholds);
printf("nCFirm Size: %d, nEmployment: %d\n", constructor_firm_size, employment_size);
}
/* Each constructor is assigned one employee */
for (i = 0; i < ncfirms; i++) {
if (nemployed > employment_size) {
if (WARNING_MODE) {
printf("Warning @jpoffice_init_employment(): There are more constructor firms then employable number of households.\n");
}
free_int_array(&household_list);
free_int_array(®ular_firm_list);
free_int_array(&constructor_firm_list);
return 0;
}
firm_id = constructor_firm_list.array[i];
household_id = household_list.array[0];
/* The employee is a manager. */
add_jpoffice_household_employer_message(household_id, firm_id, 1);
add_jpoffice_firm_employee_message(firm_id, household_id, 1);
remove_int(&household_list, 0);
nemployed++;
}
/* Each regular firm is assigned one employee */
for (i = 0; i < nrfirms; i++) {
if (nemployed > employment_size) {
if (WARNING_MODE) {
printf("Warning @jpoffice_init_employment(): There are more firms then employable number of households.\n");
}
free_int_array(&household_list);
free_int_array(®ular_firm_list);
free_int_array(&constructor_firm_list);
return 0;
}
firm_id = regular_firm_list.array[i];
household_id = household_list.array[0];
/* The employee is a manager. */
add_jpoffice_household_employer_message(household_id, firm_id, 1);
add_jpoffice_firm_employee_message(firm_id, household_id, 1);
remove_int(&household_list, 0);
nemployed++;
}
/* Each constructor is assigned additional constant employees */
for (i = 0; i < ncfirms; i++) {
firm_id = constructor_firm_list.array[0];
for (j = 1; j < constructor_firm_size; j++) {
if (nemployed > employment_size) {
if (WARNING_MODE) {
printf("Warning @jpoffice_init_employment(): Household shortage is observed at assigning additional labour to constructor firms.\n");
}
free_int_array(&household_list);
free_int_array(®ular_firm_list);
free_int_array(&constructor_firm_list);
return 0;
}
household_id = household_list.array[0];
add_jpoffice_household_employer_message(household_id, firm_id,0);
add_jpoffice_firm_employee_message(firm_id, household_id, 0);
remove_int(&household_list, 0);
nemployed++;
}
remove_int(&constructor_firm_list, 0);
}
/* Rest of households are assigned to firms randomly.
* If a normal or a scale-free distribution for firm size to be opted,
* it should be implemented hereby.
*/
do {
if (nemployed > employment_size){
break;
}
j = nrfirms - 1;
i = random_int(0, j);
firm_id = regular_firm_list.array[i];
household_id = household_list.array[0];
add_jpoffice_household_employer_message(household_id, firm_id,0);
add_jpoffice_firm_employee_message(firm_id, household_id, 0);
remove_int(&household_list, 0);
nemployed++;
} while (1);
if (PRINT_DEBUG_MODE) {
printf("Number of total employement %d\n", nemployed);
}
/* Finish */
free_int_array(&household_list);
free_int_array(®ular_firm_list);
free_int_array(&constructor_firm_list);
return 0; /* Returning zero means the agent is not removed */
}
/*
* \fn: int jpoffice_iterate()
* \brief:
*/
int jpoffice_iterate()
{
IT_NO++;
return 0; /* Returning zero means the agent is not removed */
}