Changeset a0523b8 in observatorio for simulacion/ModuloDinamico


Ignore:
Timestamp:
Jan 27, 2015, 9:06:14 AM (9 years ago)
Author:
Alejandro <amujica@…>
Branches:
simulacion
Children:
5c51ff9
Parents:
c9dd3b4
Message:

Correcciones al simulador (segunda validacion)

Location:
simulacion/ModuloDinamico
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • simulacion/ModuloDinamico/io_manager.H

    re481d13 ra0523b8  
    642642        queue.put(start_node);
    643643
    644         while (not queue.is_empty()) {
    645 
     644        while (not queue.is_empty())
     645          {
    646646            Graph::Node * src = queue.get();
    647647
    648648            Good * good = src->get_info().get();
     649
     650            Product * ptr_product = static_cast<Product *>(good);
    649651
    650652            List<Aleph::pair<Product, long>> requesters;
     
    685687                );
    686688
    687                 ip_relationship.set_purchase_price(
    688                   get_acquisition_price("N", input_id, year)
     689                ip_relationship.set_bought_quantity(
     690                  get_declared_bought_quantity(
     691                    ptr_product->get_company_rif(),
     692                    ptr_product->get_company_name(),
     693                    input_id,
     694                    year
     695                  )
    689696                );
     697
     698                ip_relationship.set_purchase_price(ptr_product->get_price());
    690699
    691700                g.insert_arc(src, tgt, ip_relationship);
     
    715724        real accum_price = 0.0;
    716725
    717         real accum_quantity = 0.0;
    718 
    719726        for (Graph::Node_Arc_Iterator nait(node); nait.has_current();
    720727             nait.next())
     
    741748            accum_price += ip_rel.get_purchase_price();
    742749
    743             accum_quantity += ip_rel.get_bought_quantity();
    744 
    745750            ++num_buyers;
    746751          }
    747752
    748753        real external_sales = 0.0;
     754
     755        real avg_price = accum_price / num_buyers;
    749756
    750757        switch (ptr_good->get_type())
     
    772779
    773780            (static_cast<Input *>(ptr_good))
    774               ->set_price(accum_price / num_buyers);
     781              ->set_price(avg_price);
    775782
    776783            break;
     
    778785          case IMPORTED_PRODUCT:
    779786            (static_cast<Imported_Product *>(ptr_good))
    780               ->set_imports(accum_quantity);
     787              ->set_imports(internal_sales / avg_price);
    781788            (static_cast<Imported_Product *>(ptr_good))
    782               ->set_sale(accum_quantity);
     789              ->set_sale(internal_sales);
    783790            (static_cast<Imported_Product *>(ptr_good))
    784               ->set_requested_quantity(accum_quantity);
     791              ->set_requested_quantity(internal_sales / avg_price);
    785792            (static_cast<Imported_Product *>(ptr_good))
    786               ->set_price(accum_price / num_buyers);
     793              ->set_price(avg_price);
    787794
    788795          }
  • simulacion/ModuloDinamico/simulator.C

    r23f4971 ra0523b8  
    6868  state_0.stock = 0.0;
    6969  state_0.internal_sales = ptr_product->get_internal_sales();
    70   state_0.external_sales = num_output_arcs == 0 ? ptr_product->get_production()
    71                          : ptr_product->get_external_sales();
    72   state_0.internal_requested_quantity = ptr_product->get_internal_sales();
    73   state_0.external_requested_quantity = state_0.external_sales;
    74 
     70  state_0.external_sales = num_output_arcs == 0 ?
     71                           ptr_product->get_production() *
     72                           ptr_product->get_price() :
     73                           ptr_product->get_external_sales();
     74  state_0.internal_requested_quantity =
     75    state_0.internal_sales / ptr_product->get_price();
     76  state_0.external_requested_quantity =
     77    state_0.external_sales / ptr_product->get_price();
    7578
    7679  state_0.num_employees = ptr_product->get_num_employees();
     
    109112  state_0.income = state_0.production * state_0.price;
    110113
    111   real investment = state_0.administrative_staff_cost +
    112                     state_0.labor_cost + state_0.input_cost;
    113 
    114   state_0.other_cost = std::abs(state_0.income - investment);
    115 
    116   investment += state_0.other_cost;
    117 
    118   state_0.total_cost = investment + state_0.other_cost;
     114  real partial_cost = state_0.administrative_staff_cost +
     115                      state_0.labor_cost + state_0.input_cost;
     116
     117  state_0.other_cost = std::abs(state_0.income - partial_cost);
     118
     119  state_0.total_cost = partial_cost + state_0.other_cost;
    119120
    120121  state_0.unitarian_administrative_staff_cost =
     
    127128  state_0.other_unitarian_cost = state_0.other_cost / state_0.production;
    128129
    129   state_0.economic_status = state_0.income - investment;
     130  state_0.economic_status = state_0.income - state_0.total_cost;
    130131
    131132  ptr_product->add_simulation_attributes(state_0);
     
    151152  state_0.internal_sales = ptr_input->get_internal_sales();
    152153  state_0.external_sales = ptr_input->get_external_sales();
    153   state_0.internal_requested_quantity = ptr_input->get_internal_sales();
    154   state_0.external_requested_quantity = ptr_input->get_external_sales();
     154  state_0.internal_requested_quantity =
     155    state_0.internal_sales / ptr_input->get_price();
     156  state_0.external_requested_quantity =
     157    state_0.external_sales / ptr_input->get_price();
    155158  state_0.price = ptr_input->get_price();
    156159
     
    183186void init_network(Graph & network)
    184187{
     188  Exogenous_Variables & exo_var = Exogenous_Variables::get_instance();
     189
     190  exo_var.set_average_salary(exo_var.get_average_salary() * NUM_MONTHS);
     191
    185192  for (Graph::Node_Iterator it(network); it.has_current(); it.next())
    186193    {
     
    223230/* Una red productiva es realmente un digrafo, la red fue modelada con grafo
    224231   para poder efectuar navegación hacia los nodos de atrás. Para esta
    225    construcción se asume una convención de que uno nodo que si el nodo s va
    226    detrás de t, en un digrafo el arco sería s -> t y en el grafo se respeta ese
    227    orden teniendo los arcos s -- t.
     232   construcción se asume una convención de que si el nodo s va detrás de t,
     233   en un digrafo el arco sería s -> t y en el grafo se respeta ese orden
     234   teniendo los arcos s -- t.
    228235
    229236   Esta función toma el grafo y lo convierte en un digrafo para aplicar sobre
    230    este último el algoritmo de construcción de rangos topológicos.
     237   éste el algoritmo de construcción de rangos topológicos.
    231238
    232239   En los nodos del digrafo se almacenan los punteros a los nodos del grafo y
     
    234241   requeridos para hacer los recorridos por el grafo por cada nivel topológico
    235242   desde el más alto hasta el más bajo, pero finalmente el proceso de simulación
    236    se efectúa sobre los nodos del grafo porque se requiere navegación hacia
    237    atrás.
     243   se efectúa sobre los nodos del grafo (y no los del digrafo) porque se
     244   requiere navegación hacia atrás.
    238245*/
    239246void graph_to_digraph(Graph & graph, Digraph & digraph)
     
    728735                                 const size_t & t)
    729736{
    730   Exogenous_Variables & exo_var = Exogenous_Variables::get_instance();
    731 
    732737  const real & new_price = node->get_info()->price_at(t);
    733738
     
    748753
    749754      // Al precio de venta se le incrementa la tasa de ganancia.
    750       sim_attr.purchase_price = new_price *
    751                                 (1.0 + exo_var.rate_of_gain_at(t) / 100.0);
     755      sim_attr.purchase_price = new_price;
    752756    }
    753757}
     
    819823  // Cálculo de costos administrativos
    820824  sim_attr_t.administrative_staff_cost =
    821     ptr_product->get_num_administrative_staff() * wage;
     825    ptr_product->get_num_administrative_staff() * sim_attr_t.integral_wage;
    822826  sim_attr_t.unitarian_administrative_staff_cost =
    823827    sim_attr_t.administrative_staff_cost / sim_attr_t.production;
    824828
    825829  // Cálculo de costos en mano de obra
    826   sim_attr_t.labor_cost = sim_attr_t.num_employees * wage;
     830  sim_attr_t.labor_cost = sim_attr_t.num_employees * sim_attr_t.integral_wage;
    827831  sim_attr_t.unitarian_labor_cost =
    828832    sim_attr_t.labor_cost / sim_attr_t.production;
     
    850854                          sim_attr_t.other_cost;
    851855
    852   sim_attr_t.price = sim_attr_t.unitarian_administrative_staff_cost +
     856  sim_attr_t.price = (sim_attr_t.unitarian_administrative_staff_cost +
    853857                     sim_attr_t.unitarian_labor_cost +
    854858                     sim_attr_t.input_cost_per_unit +
    855                      sim_attr_t.other_unitarian_cost;
     859                     sim_attr_t.other_unitarian_cost)  *
     860                     (1.0 + exo_var.rate_of_gain_at(t) / 100.0);
     861
     862  sim_attr_t.internal_sales *= sim_attr_t.price;
     863
     864  sim_attr_t.external_sales *= sim_attr_t.price;
    856865
    857866  update_price_in_output_arcs(network, node, t);
    858867
     868  sim_attr_t.economic_status = sim_attr_t.income - sim_attr_t.total_cost;
    859869}
    860870
     
    877887  sim_attr_t.price = sim_attr_t_1.price *
    878888                     (1.0 + exo_var.rate_of_price_change_at(t) / 100.0);
     889
     890  sim_attr_t.internal_sales *= sim_attr_t.price;
     891
     892  sim_attr_t.external_sales *= sim_attr_t.price;
    879893
    880894  update_price_in_output_arcs(network, node, t);
  • simulacion/ModuloDinamico/simulator.H

    r8eb9820 ra0523b8  
    4040# define RANDOM_UNIF(a, b) (gsl_rng_uniform(rng) * ((b) - (a)) + (a))
    4141
    42 # define DAYS_IN_A_YEAR 360
     42# define DAYS_IN_A_MONTH 30
     43
     44# define NUM_MONTHS 12
     45
     46# define DAYS_IN_A_YEAR (DAYS_IN_A_MONTH * NUM_MONTHS)
    4347
    4448# define WAGE_PROPORTION 0.4
    4549
    46 # define UT_PROPORTION 0.25
     50# define UT_PROPORTION 0.5
    4751
    4852typedef Graph_Node<Graph::Node *> D_Node;
Note: See TracChangeset for help on using the changeset viewer.