ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
firm_functions_production.c
Go to the documentation of this file.
1 #include "../header.h"
2 #include "../firm_agent_header.h"
3 #include "../library_header.h"
4 #include <math.h>
5 
6 /*
7  * \fn: int firm_production_skip()
8  * \brief: Firm skips the production for the current turn.
9  */
11 {
12  ISINSOLVENT = 0;
13  EMPLOYEES_NEEDED = 1;
14 
15  return 0; /* Returning zero means the agent is not removed */
16 }
17 
18 /*
19  * \fn: int firm_production_produce_goods()
20  * \brief: Firm releases number of items produced.
21  */
23 {
24  /*
25  Production amount based on Lentoif production function.
26  Capital productivity is set to inf. This results in a production solely based on availability
27  of labour.
28  */
30 
31  /* Update of the inventory available for sell is updated at the first day of the month.*/
32  //INVENTORY += PRODUCTION_CURRENT;
33 
34  /*This is possible if and only if an insolvent firms owner/manager goes turnover.*/
35  if (NO_EMPLOYEES < 1) {
37  if (WARNING_MODE) {
38  printf("Warning @firm_production_produce_goods(): Firm Id = %d, has lost her only employee through employee turnover! \n", ID);
39  }
40  }
41 
42  return 0; /* Returning zero means the agent is not removed */
43 }
44 
45 /*
46  * \fn: int firm_production_set_price()
47  * \brief: Firm sets price of goods produced.
48  */
50 {
51  int goods_to_sale = 0;
52  double unit_cost_old, unit_cost_new;
53 
54  /* Excluding newly finished goods at cost computation. */
55  unit_cost_old = UNIT_COST;
56 
57  /* The update of the inventory is not made yet. */
58  goods_to_sale = INVENTORY + PRODUCTION_CURRENT;
59 
60  unit_cost_new = WAGE_OFFER * (double)NO_EMPLOYEES;
61  unit_cost_new += DEBT * LOANS_INTEREST_RATE / 12;
62  unit_cost_new = unit_cost_new / PRODUCTION_CURRENT;
63 
64  if (goods_to_sale != 0) {
65  UNIT_COST = ((INVENTORY * unit_cost_old) + (PRODUCTION_CURRENT * unit_cost_new) ) / goods_to_sale;
67  }
68 
69  return 0; /* Returning zero means the agent is not removed */
70 }
71 
72 /*
73  * \fn: int firm_production_plan()
74  * \brief: Firm determines number of items to be produced for the next period.
75  * It updates inventory accordingly.
76  */
78 {
79 
80  /* Estimate the production for next period. */
81  if (INVENTORY == 0) {
82  EXPECTED_SALES = (int) ((1.0 + PRODUCTION_MARKUP) * SALES);
83  }
84  else{
86  }
87 
88  int goods_to_sale = INVENTORY + PRODUCTION_CURRENT;
89  if ((goods_to_sale - EXPECTED_SALES) >= 0) {
90  PRODUCTION_PLAN = 0;
91  } else {
92  PRODUCTION_PLAN = EXPECTED_SALES - (goods_to_sale - EXPECTED_SALES);
93  }
94 
95 
96  /* Computing production plan considering firm memory persistance and production estimates.
97  */
98  PRODUCTION_PLAN = (int) (FIRM_MEMORY_PERSISTANCE * PRODUCTION_CURRENT + (1.0 - FIRM_MEMORY_PERSISTANCE) * PRODUCTION_PLAN);
99 
100  if (PRINT_DEBUG_MODE) {
101  printf("Firm Id = %d, I = %d, PC = %d, GtoS = %d, S = %d, ES = %d, PP = %d\n", ID, INVENTORY, PRODUCTION_CURRENT, goods_to_sale, SALES, EXPECTED_SALES, PRODUCTION_PLAN);
102  }
103 
104 
106  char * filename;
107  FILE * file1;
108  filename = malloc(100*sizeof(char));
109  filename[0]=0;
110  int needed = ceil(PRODUCTION_PLAN / LABOUR_PRODUCTIVITY);
111  if (needed < 1) {needed = 1;}
112  strcpy(filename, "./outputs/data/Firm_Monthly.txt");
113  file1 = fopen(filename,"a");
114  fprintf(file1,"%d %d %f %d %d %d %d %d %d %f\n",IT_NO, ID, WAGE_OFFER, NO_EMPLOYEES, EMPLOYEES_NEEDED, SALES, INVENTORY, PRODUCTION_CURRENT, PRODUCTION_PLAN, UNIT_GOODS_PRICE);
115 
116  fclose(file1);
117  free(filename);
118  }
119 
120  /* Update is made here to prevent any sales of new products right at the end of the month. */
122 
123  /*This case has been observed during the experiment. Production model should be revised!*/
124  if (PRODUCTION_PLAN < 0) {
126  if (WARNING_MODE) {
127  printf("Warning @firm_production_plan(): A negative production planning occurred Firm ID = %d, previous sales is targeted instead, Sales = %d\n", ID, SALES);
128  }
129  }
130 
131  /* Sales are reset to 0 for monthly periods. */
132  SALES = 0;
133 
134 
135  return 0; /* Returning zero means the agent is not removed */
136 }
137 
138 /*
139  * \fn: firm_production_compute_labour_demand()
140  * \brief: Firm determines required number of labourers for current
141  * production plan.
142  */
144 {
146 
147  if (EMPLOYEES_NEEDED < 1) {EMPLOYEES_NEEDED = 1;}
148 
149  return 0; /* Returning zero means the agent is not removed */
150 }
151 
152 
153 /*
154  * Constructor Firm Roles:
155  */
156 
157 
158 /*
159  * \fn: int firm_production_construct_houses()
160  * \brief: Firm releases number of houses completed.
161  */
163 {
164  int capital, labour, units_to_produce;
165 
166 
167  labour = (int)(NO_EMPLOYEES * LABOUR_PRODUCTIVITY);
168  capital = (int) (CAPITAL_PRODUCTIVITY * CAPITAL_GOODS);
169 
170  /* Lentoif production function: */
171  units_to_produce = min_int(labour, capital);
172 
173  /* Finished goods were transfered to inventories.
174  Unfinished housing units are advanced one at a time.
175  */
176  PROJECTS[0] = 0;
177 
178  while (units_to_produce > 0) {
179  for(int i = 0; i<=10; i++) {
180  if (units_to_produce <= 0) {break;}
181  if (PROJECTS[i+1] == 0) {continue;}
182  PROJECTS[i] += 1;
183  PROJECTS[i+1] -= 1;
184  units_to_produce -=1;
185  }
186  if (units_to_produce > 0) {
187  PROJECTS[11] += 1;
188  units_to_produce -= 1;
189  }
190  }
191  /*
192  for (int i = 1; i<=12; i++) {
193  if (units_to_produce == 0) { break; }
194  if (PROJECTS[i] <= units_to_produce) {
195  PROJECTS[i-1] += PROJECTS[i];
196  units_to_produce -= PROJECTS[i];
197  PROJECTS[i] = 0;
198  } else {
199  PROJECTS[i-1] += units_to_produce;
200  PROJECTS[i] -= units_to_produce;
201  units_to_produce = 0;
202  }
203  }
204  if (units_to_produce > 0) {
205  PROJECTS[12] += units_to_produce;
206  }
207  */
208 
210 
211  if (PRINT_DEBUG_MODE) {
212  printf("Constructor Firm %d produces %d houses.\n", ID, PRODUCTION_CURRENT);
213  }
214 
215  return 0; /* Returning zero means the agent is not removed */
216 }
217 
218 
219 /*
220  * \fn: int firm_production_construction_plan()
221  * \brief: Firm determines number of housing units to be constructed for the next period.
222  */
224 {
225  int work_in_progress;
226  int maxsize;
227  int last_production;
228 
229  /* Those housing units which are produced in previous month are made
230  available for sale at the start of current month.
231  */
233  last_production = PRODUCTION_CURRENT;
234  PRODUCTION_CURRENT = 0;
235 
236 
237  /* Getting number of ongoing projects. */
238  work_in_progress = 0;
239 
240  for (int i = 1; i<=11; i++) {
241  work_in_progress += PROJECTS[i];
242  }
243 
244  maxsize = (int) (CAPITAL_PRODUCTIVITY * CAPITAL_GOODS);
245 
246  /* Some conditions are added to the model! Needs to be double chekced.*/
247  if (maxsize <= 0){
248  PRODUCTION_PLAN = 0;
249  }
250  else if (DELTA_HOUSING_PRICE >= 0){
251  if (work_in_progress < maxsize) {
252  PRODUCTION_PLAN = random_int(work_in_progress, maxsize);
253  } else {
254  PRODUCTION_PLAN = maxsize;
255  }
256  }
257  else {
258  if (work_in_progress < 2) {
259  PRODUCTION_PLAN = work_in_progress;
260  } else {
261  PRODUCTION_PLAN = random_int(1, work_in_progress);
262  }
263  }
264 
266  char * filename;
267  FILE * file1;
268  filename = malloc(100*sizeof(char));
269  filename[0]=0;
270 
271  int needed = ceil(PRODUCTION_PLAN / LABOUR_PRODUCTIVITY);
272  if (needed < 1) {needed = 1;}
273  strcpy(filename, "./outputs/data/Constructor_Firm_Monthly.txt");
274  file1 = fopen(filename,"a");
275  fprintf(file1,"%d %d %f %d %d %d %d %d %d %f\n",IT_NO, ID, WAGE_OFFER, NO_EMPLOYEES, needed, SALES, INVENTORY, last_production, PRODUCTION_PLAN, UNIT_HOUSE_PRICE);
276 
277  fclose(file1);
278  free(filename);
279  }
280 
281  /* Sales are reset to 0 for monthly periods. */
282  SALES = 0;
283 
284  return 0; /* Returning zero means the agent is not removed */
285 }
286 
287 /*
288  * \fn: firm_production_construction_labour_demand()
289  * \brief: Firm determines required number of workers for current
290  * construction plan.
291  */
293 {
295 
296  if (EMPLOYEES_NEEDED < 1) {EMPLOYEES_NEEDED = 1;}
297 
298  return 0; /* Returning zero means the agent is not removed */
299 }