ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
jpoffice_functions_labour.c
Go to the documentation of this file.
1 #include "../header.h"
2 #include "../jpoffice_agent_header.h"
3 #include "../library_header.h"
4 
5 /*
6  * \fn: int jpoffice_labour_stage1
7  * \brief: The function collects vacancies and jop applications.
8  * The function performs jop placement. Lower indexed households
9  * have priority.
10  */
12 {
13 
14  /* Allocate local vacancies and applicants. */
15  vacancy_array vacancy_list;
16  employee_array applicant_list;
17  int firm_id, household_id;
18  double current_wage, wage_offer;
19  int i,j;
20 
21  init_vacancy_array(&vacancy_list);
22  init_employee_array(&applicant_list);
23 
24  /* Collect vacancies */
27  wage_offer = vacancy_stage1_message->wage;
28  /* Add vacancy to the list */
29  add_vacancy(&vacancy_list, firm_id, wage_offer);
31 
32  /* Collect job applications */
34 
36  current_wage = job_application_stage1_message->wage;
37 
38  /* Add applicant to the list */
39  add_employee(&applicant_list, household_id, current_wage);
40 
42 
43  /* Do the matching: */
44 
45  /* Input assumptions:
46  * applicants are sorted ascendingly by household id.
47  * vacancies are sorted descendingly by wage.
48  * messages are sorted and listed fullfilling above requirements.
49  */
50  i = 0;
51  j = 0;
52  do {
53  /* No applicants recieved. */
54  if (applicant_list.size == 0 ) { break; }
55  /* No vacancies posted. */
56  if (vacancy_list.size == 0 ) { break; }
57  /* No unemployed left. */
58  if (i == applicant_list.size) { break;}
59  /* no positions left. */
60  if (j == vacancy_list.size) { break; }
61 
62  if (vacancy_list.array[j].wage > applicant_list.array[i].wage) {
63  wage_offer = vacancy_list.array[j].wage;
64  household_id = applicant_list.array[i].id;
65  firm_id = vacancy_list.array[j].id;
66  /* Send out job matching messages. */
67  add_job_match_stage1_message(firm_id, household_id, wage_offer);
68  /* Proceed with matching. */
69  i++;
70  j++;
71  } else {
72  /* Current applicant's wage is higher than any of vacancies left proceed with next applicant.
73  */
74  i++;
75  }
76 
77  } while (1);
78 
79  /* Finish */
80  if (PRINT_DEBUG_MODE) {
81  printf("Stage 1 Employment Summary: Applicants: %d, Vacancy: %d, Placement: %d \n", applicant_list.size, vacancy_list.size, j);
82  }
83 
84  /* Free vacancies */
85  free_vacancy_array(&vacancy_list);
86 
87  /* Free applications */
88  free_employee_array(&applicant_list);
89 
90  return 0; /* Returning zero means the agent is not removed */
91 }
92 
93 /*
94  * \fn: int jpoffice_labour_stage2
95  * \brief: The function collects still open vacancies and list of
96  * unemployed households.
97  * The function performs jop placament. Lower indexed households have
98  * priority.
99  */
101 {
102 
103  /* Allocate local vacancies and applicants. */
104  vacancy_array vacancy_list;
105  int_array applicant_list;
106  int firm_id, household_id;
107  double wage_offer;
108  int i,j;
109 
110  /* Initialize */
111  init_vacancy_array(&vacancy_list);
112  init_int_array(&applicant_list);
113 
116  wage_offer = vacancy_stage2_message->wage;
117  /* Add vacancy to the list */
118  add_vacancy(&vacancy_list, firm_id, wage_offer);
120 
123  /* Add applicant to the list */
124  add_int(&applicant_list, household_id);
126 
127  /* Do the matching
128  * Input assumptions:
129  * applicants are sorted ascendingly by household id.
130  * vacancies are sorted descendingly by wage.
131  * messages are sorted and listed fullfilling above requirements.
132  */
133  i = 0;
134  j = 0;
135  do {
136  if (applicant_list.size == 0 ) {break;}
137  if (vacancy_list.size == 0 ) {break;}
138  if (i == applicant_list.size) {break;}
139  if (j == vacancy_list.size) {break;}
140 
141  wage_offer = vacancy_list.array[j].wage;
142  household_id = applicant_list.array[i];
143  firm_id = vacancy_list.array[j].id;
144  add_job_match_stage2_message(firm_id, household_id, wage_offer);
145  i++;
146  j++;
147  } while (1);
148 
149 
150  /* Finish */
151  if (PRINT_DEBUG_MODE) {
152  printf("Stage 2 Employment Summary: Applicants: %d, Vacancy: %d, Placement: %d \n", applicant_list.size, vacancy_list.size, j);
153  }
154 
155  /* Free vacancies */
156  free_vacancy_array(&vacancy_list);
157  /* Free applications */
158  free_int_array(&applicant_list);
159 
160  return 0; /* Returning zero means the agent is not removed */
161 }