2 #include "../mall_agent_header.h"
3 #include "../library_header.h"
20 int firm_id, inventory;;
21 double price, inv_price;
22 double denominator = 0;
29 if (price < min_price) {
32 if (price > max_price) {
36 if (price > 0 && inventory > 0) {
39 denominator += inv_price;
40 add_seller(&sellers_list, firm_id, price, inventory, inv_price);
42 else if (inventory <= 0){
44 printf(
"Warning @mall_consumption_shopping(): An invalid inventory = %d is received from Firm ID = %d\n", inventory, firm_id);
49 printf(
"Warning @mall_consumption_shopping(): An invalid price = %f is received from Firm ID = %d\n", price, firm_id);
70 printf(
"Warning @mall_consumption_shopping(): An invalid budget = %f is received from Household ID = %d\n", budget, hh_id);
83 double denominator_temp;
86 double transaction_volume;
91 double total_volume = 0;
92 int transaction_occured;
95 if (sellers_list.
size == 0 || buyers_list.
size == 0) {
break;}
97 hh_id = buyers_list.
array[0].
id;
104 if (budget < price) {
110 select_prob = (double)
random_int(0, 99) / 100;
112 transaction_size = 0;
113 transaction_volume = 0;
114 transaction_occured = 0;
115 for (ind = 0; ind < sellers_list.
size; ind++) {
117 firm_id = sellers_list.
array[ind].
id;
118 if (inventory <= 0) {
121 printf(
"Warning @mall_consumption_shopping(): An invalid inventory = %d is detected while processing Firm ID = %d\n", inventory, firm_id);
131 if (budget <= price) {
132 denominator_temp = inv_price_cum;
133 if (denominator_temp <= 0) {
135 printf(
"Warning @mall_consumption_shopping(): An invalid state is detected while processing Household ID = %d\n", hh_id);
141 for (i = 0; i <= ind; i++) {
144 if ((inv_price_cum / denominator_temp - select_prob) >= 0) {
145 transaction_size = (int) floor(budget / price);
146 if (transaction_size > inventory){
147 transaction_size = inventory;
150 transaction_volume = transaction_size * price;
151 budget -= transaction_volume;
156 total_sold += transaction_size;
157 total_volume += transaction_volume;
159 inventory -= transaction_size;
160 if (inventory == 0) {
167 transaction_occured = 1;
176 if ((inv_price_cum / denominator - select_prob) >= 0) {
177 transaction_size = (int) floor(budget / price);
178 if (transaction_size > inventory){
179 transaction_size = inventory;
182 transaction_volume = transaction_size * price;
183 budget -= transaction_volume;
188 total_sold += transaction_size;
189 total_volume += transaction_volume;
191 inventory -= transaction_size;
192 if (inventory == 0) {
199 transaction_occured = 1;
205 if (transaction_occured == 0) {
207 printf(
"Warning @mall_consumption_shopping(): Transaction did not take place while processing Household ID = %d\n", hh_id);
215 if (total_sold > 0) {
437 filename = malloc(100*
sizeof(
char));
439 strcpy(filename,
"./outputs/data/Mall_snapshot.txt");
441 file1 = fopen(filename,
"a");
442 fprintf(file1,
"%d %d %f\n",
IT_NO, quantity, price);
450 printf(
"Mall posts weekly transaction summaries. \n");