Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions declared twice with two draws2data2draws in one model #14

Open
hyunjimoon opened this issue Nov 11, 2022 · 2 comments
Open

Functions declared twice with two draws2data2draws in one model #14

hyunjimoon opened this issue Nov 11, 2022 · 2 comments

Comments

@hyunjimoon
Copy link
Contributor

Semantic error in '/Users/hyunjimoon/Dropbox/15879-Fall2022/Homeworks/HW7/stanify/stan_files/Inven_6est/Inven_6est_functions.stan', line 65, column 0, included from
'/Users/hyunjimoon/Dropbox/15879-Fall2022/Homeworks/HW7/stanify/stan_files/Inven_6est/Inven_6est_draws2data.stan', line 2, column 0:
   -------------------------------------------------
    63:  }
    64:  
    65:  real lookupFunc__table_for_order_fulfillment(real x){
         ^
    66:      // x (0, 2) = (0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.0)
    67:      // y (0, 1) = (0.0, 0.2, 0.4, 0.58, 0.73, 0.85, 0.93, 0.97, 0.99, 1.0, 1.0, 1.0)
   -------------------------------------------------

Function 'lookupFunc__table_for_order_fulfillment' has already been declared to for signature 
(real) => real
make: *** [/Users/hyunjimoon/Dropbox/15879-Fall2022/Homeworks/HW7/stanify/stan_files/Inven_6est/Inven_6est_draws2data.hpp] Error 1

Command ['make', 'STANCFLAGS+=--include-paths=/Users/hyunjimoon/Dropbox/15879-Fall2022/Homeworks/HW7/stanify/stan_files/Inven_6est', '/Users/hyunjimoon/Dropbox/15879-Fall2022/Homeworks/HW7/stanify/stan_files/Inven_6est/Inven_6est_draws2data']
	error during processing No such file or directory

when I checked stan function file, functions were declared twice

real lookupFunc__table_for_order_fulfillment(real x){
    // x (0, 2) = (0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.0)
    // y (0, 1) = (0.0, 0.2, 0.4, 0.58, 0.73, 0.85, 0.93, 0.97, 0.99, 1.0, 1.0, 1.0)
    real slope;
    real intercept;

    if(x <= 0.2){
        intercept = 0.0;
        slope = (0.2 - 0.0) / (0.2 - 0.0);
        return intercept + slope * (x - 0.0);
    }
   ...
    else if(x <= 2.0){
        intercept = 1.0;
        slope = (1.0 - 1.0) / (2.0 - 2.0);
        return intercept + slope * (x - 2.0);
    }
    return 1.0;
}

real lookupFunc__table_for_order_fulfillment(real x){
    // x (0, 2) = (0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.0)
    // y (0, 1) = (0.0, 0.2, 0.4, 0.58, 0.73, 0.85, 0.93, 0.97, 0.99, 1.0, 1.0, 1.0)
    real slope;
    real intercept;

    if(x <= 0.2){
        intercept = 0.0;
        slope = (0.2 - 0.0) / (0.2 - 0.0);
        return intercept + slope * (x - 0.0);
    }
   ...
    else if(x <= 2.0){
        intercept = 1.0;
        slope = (1.0 - 1.0) / (2.0 - 2.0);
        return intercept + slope * (x - 2.0);
    }
    return 1.0;
}

// Begin ODE declaration
real dataFunc__customer_order_rate(real time, real time_step){
    // DataStructure for variable customer_order_rate
    real slope;
    real intercept;

    if(time <= time_step * 1){
        intercept = 146376;
        real local_time_step = time_step * 1 - time_step * 0;
        slope = (147079 - 146376) / local_time_step;
        return intercept + slope * (time - time_step * 0);
    }
   ...
    else if(time <= time_step * 19){
        intercept = 183682;
        real local_time_step = time_step * 19 - time_step * 18;
        slope = (183318 - 183682) / local_time_step;
        return intercept + slope * (time - time_step * 18);
    }
    return 183318;
}

real dataFunc__process_noise_uniform_driving(real time, real time_step){
    // DataStructure for variable process_noise_uniform_driving
    real slope;
    real intercept;

    if(time <= time_step * 1){
        intercept = 0.1236860198383215;
        real local_time_step = time_step * 1 - time_step * 0;
        slope = (-0.35346438681712344 - 0.1236860198383215) / local_time_step;
        return intercept + slope * (time - time_step * 0);
...
    else if(time <= time_step * 19){
        intercept = 0.38848170528082115;
        real local_time_step = time_step * 19 - time_step * 18;
        slope = (-0.4071190492640847 - 0.38848170528082115) / local_time_step;
        return intercept + slope * (time - time_step * 18);
    }
    return -0.4071190492640847;
}

real dataFunc__customer_order_rate(real time, real time_step){
    // DataStructure for variable customer_order_rate
    real slope;
    real intercept;

    if(time <= time_step * 1){
        intercept = 146376;
        real local_time_step = time_step * 1 - time_step * 0;
        slope = (147079 - 146376) / local_time_step;
        return intercept + slope * (time - time_step * 0);
    }
    ...
    else if(time <= time_step * 19){
        intercept = 0.38848170528082115;
        real local_time_step = time_step * 19 - time_step * 18;
        slope = (-0.4071190492640847 - 0.38848170528082115) / local_time_step;
        return intercept + slope * (time - time_step * 18);
    }
    return -0.4071190492640847;
}

vector vensim_ode_func(real time, vector outcome, real time_step, real wip_adjustment_time, real safety_stock_coverage, real target_delivery_delay, real minimum_order_processing_time, real process_noise_scale, real manufacturing_cycle_time, real inventory_adjustment_time){
    vector[7] dydt;  // Return vector of the ODE function

    // State variables
    real expected_order_rate = outcome[1];
    real process_noise = outcome[2];
    real work_in_process_inventory = outcome[3];
    real backlog = outcome[4];
    real production_rate_stocked = outcome[5];
    real inventory = outcome[6];
    real production_start_rate_stocked = outcome[7];

    real desired_inventory_coverage = minimum_order_processing_time + safety_stock_coverage;
    real desired_inventory = desired_inventory_coverage * expected_order_rate;
    real adjustment_from_inventory = (desired_inventory - inventory) / inventory_adjustment_time;
    real desired_production = fmax(0, expected_order_rate + adjustment_from_inventory);
    real desired_wip = manufacturing_cycle_time * desired_production;
    real adjustment_for_wip = (desired_wip - work_in_process_inventory) / wip_adjustment_time;
    real desired_production_start_rate = fmax(0, desired_production + adjustment_for_wip);
    real production_start_rate = fmax(0, desired_production_start_rate);
    real desired_minus_shadow_psr = production_start_rate - production_start_rate_stocked;
    real production_start_rate_stocked_change_rate = desired_minus_shadow_psr / time_step;
    real desired_shipment_rate = backlog / target_delivery_delay;
    real production_rate = work_in_process_inventory / manufacturing_cycle_time * fmax(0, 1 + process_noise);
    real desired_minus_shadow_pr = production_rate - production_rate_stocked;
    real production_rate_stocked_change_rate = desired_minus_shadow_pr / time_step;
    real production_rate_stocked_dydt = production_rate + production_rate_stocked_change_rate;
    real time_to_average_order_rate = 8;
    real change_in_exp_orders = (dataFunc__customer_order_rate(time, time_step) - expected_order_rate) / time_to_average_order_rate;
    real maximum_shipment_rate = inventory / minimum_order_processing_time;
    real order_fulfillment_ratio = lookupFunc__table_for_order_fulfillment(maximum_shipment_rate / desired_shipment_rate);
    real correlation_time_over_time_step = 100;
    real white_noise = 4.89 * correlation_time_over_time_step ^ 0.5 * dataFunc__process_noise_uniform_driving(time, time_step) * process_noise_scale;
    real shipment_rate = desired_shipment_rate * order_fulfillment_ratio;
    real order_fulfillment_rate = shipment_rate;
    real order_rate = dataFunc__customer_order_rate(time, time_step);
    real backlog_dydt = order_rate - order_fulfillment_rate;
    real white_minus_process = white_noise - process_noise;
    real correlation_time = time_step * correlation_time_over_time_step;
    real process_noise_change_rate = white_minus_process / correlation_time;
    real expected_order_rate_dydt = change_in_exp_orders;
    real production_start_rate_stocked_dydt = production_start_rate + production_start_rate_stocked_change_rate;
    real process_noise_dydt = process_noise_change_rate;
    real work_in_process_inventory_dydt = production_start_rate - production_rate;
    real inventory_dydt = production_rate - shipment_rate;

    dydt[1] = expected_order_rate_dydt;
    dydt[2] = process_noise_dydt;
    dydt[3] = work_in_process_inventory_dydt;
    dydt[4] = backlog_dydt;
    dydt[5] = production_rate_stocked_dydt;
    dydt[6] = inventory_dydt;
    dydt[7] = production_start_rate_stocked_dydt;

    return dydt;
}

@hyunjimoon hyunjimoon changed the title Declared again with two draws2data2draws in one model Functions declared twice with two draws2data2draws in one model Nov 11, 2022
@hyunjimoon
Copy link
Contributor Author

This disappeared after @Dashadower's e621504
precedence fix but the two seems unrelated.

I recall. among the two existing fixes (one fundamental than the other) we chose the less fundamental one. This error report seems to be a problem from a root, so I am perplexed how the above commit fixed this issue.

@hyunjimoon
Copy link
Contributor Author

Dashadower thinks it is unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant