Commit ae32b4f5 authored by Loris Croce's avatar Loris Croce
Browse files

fixed flow dynamics config

parent 9e4fd674
Pipeline #38124 passed with stages
in 4 minutes and 36 seconds
0, Ble, 1.2, Inputs, minimal
0, Conserves, 0.5 , Produced, minimal
365, Fromage, 2, Produced, minimal
365, Raisin, 0.8, Inputs, minimal
730, Lait, 1.3, Required, minimal
730, Vin, 1.1, Produced, minimal
1095, Pain, 1.1, Produced, minimal
1095, Carottes, 0.9, Required, minimal
0,Ble,1.2,Inputs,minimal
0,Conserves,0.5,Produced,minimal
365,Fromage,2,Produced,minimal
365,Raisin,0.8,Inputs,minimal
730,Lait,1.3,Required,minimal
730,Vin,1.1,Produced,minimal
1095,Pain,1.1,Produced,minimal
1095,Carottes,0.9,Required,minimal
......@@ -40,8 +40,8 @@ public class FlowDynamics extends Dynamics {
}
@Override
public void process(SimulationContext context, List<GeoArea> geoAreas, List<Farmer> farmers, Flow global, Parameters parameters,
TimeUnit timeUnit) {
public void process(SimulationContext context, List<GeoArea> geoAreas, List<Farmer> farmers, Flow global,
Parameters parameters, TimeUnit timeUnit) {
Map<String, Float> inputsMod = new HashMap<>();
Map<String, Float> requiredMod = new HashMap<>();
......@@ -50,39 +50,37 @@ public class FlowDynamics extends Dynamics {
for (int i = counter; i < scenario.size(); i++) {
// checking timestep
if (Integer.parseInt(scenario.get(counter)[0]) == context.getTimestep()) {
for (GeoArea geoArea: geoAreas) {
for (GeoArea geoArea : geoAreas) {
// checking geoArea
if (scenario.get(counter)[4] == geoArea.getLabel()) {
if (scenario.get(i)[4] == geoArea.getLabel()) {
// checking flowtype
if (scenario.get(counter)[3] == "Inputs") {
inputsMod.put(scenario.get(counter)[1], Float.parseFloat(scenario.get(counter)[2]));
} else if (scenario.get(counter)[3] == "Required") {
requiredMod.put(scenario.get(counter)[1], Float.parseFloat(scenario.get(counter)[2]));
} else if (scenario.get(counter)[3] == "Produced") {
producedMod.put(scenario.get(counter)[1], Float.parseFloat(scenario.get(counter)[2]));
if (scenario.get(i)[3].equals("Inputs")) {
inputsMod.put(scenario.get(i)[1], Float.parseFloat(scenario.get(i)[2]));
} else if (scenario.get(i)[3].equals("Required")) {
requiredMod.put(scenario.get(i)[1], Float.parseFloat(scenario.get(i)[2]));
} else if (scenario.get(i)[3].equals("Produced")) {
producedMod.put(scenario.get(i)[1], Float.parseFloat(scenario.get(i)[2]));
}
}
for (Flow flow : geoArea.getFlows()) {
editInputs(counter, flow, inputsMod);
editRequirements(counter, flow, requiredMod);
editProduced(counter, flow, producedMod);
editInputs(context.getTimestep(), flow, inputsMod);
editRequirements(context.getTimestep(), flow, requiredMod);
editProduced(context.getTimestep(), flow, producedMod);
}
}
counter = i;
counter++;
} else {
break;
}
}
}
//TODO test methods below
/**
* Changes the maximum value of inputs
*
* @param timestep current timestep
* @param flow selected flow
* @param mods product label → factor map
* @param flow selected flow
* @param mods product label → factor map
*/
public void editInputs(int timestep, Flow flow, Map<String, Float> mods) {
for (Flow.Input input : flow.getInputs()) {
......@@ -97,9 +95,10 @@ public class FlowDynamics extends Dynamics {
/**
* Changes the value of requirements
*
* @param timestep current timestep
* @param flow selected flow
* @param mods product label → factor map
* @param flow selected flow
* @param mods product label → factor map
*/
public void editRequirements(int timestep, Flow flow, Map<String, Float> mods) {
for (Product required : flow.getRatio().getRequired().keySet()) {
......@@ -115,9 +114,10 @@ public class FlowDynamics extends Dynamics {
/**
* Changes the value of produced
*
* @param timestep current timestep
* @param flow selected flow
* @param mods product label → factor map
* @param flow selected flow
* @param mods product label → factor map
*/
public void editProduced(int timestep, Flow flow, Map<String, Float> mods) {
for (Product produced : flow.getRatio().getProduced().keySet()) {
......
package fr.inrae.agriterix.simulator.dynamics;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvException;
import fr.inrae.agriterix.simulator.*;
import fr.inrae.agriterix.simulator.Flow.Input;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -11,17 +16,19 @@ import java.util.stream.Collectors;
public class MarketDynamics extends Dynamics {
// TODO make it in/out parameters by geoArea/product
private static float EXPORT_FACTOR = 0.8f;
private static float IMPORT_FACTOR = 0.6f;
private float EXPORT_FACTOR;
private float IMPORT_FACTOR;
private Stocks localExchanged = new Stocks();
private Stocks importation = new Stocks();
private Stocks exportation = new Stocks();
private List<String[]> scenario;
private int counter;
public MarketDynamics() {
initLogger();
assert EXPORT_FACTOR < 1f;
assert IMPORT_FACTOR < 1f;
assert EXPORT_FACTOR <= 1f;
assert IMPORT_FACTOR <= 1f;
}
@Override
......@@ -32,12 +39,29 @@ public class MarketDynamics extends Dynamics {
@Override
public void initParameters() {
//TODO load import_export.csv
try (CSVReader reader = new CSVReader(new FileReader(configPath + "import_export.csv"))) {
scenario = reader.readAll();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (CsvException e) {
e.printStackTrace();
}
}
@Override
public void process(SimulationContext context, List<GeoArea> geoAreas, List<Farmer> farmers, Flow global,
Parameters parameters, TimeUnit timeUnit) {
// for (int i = counter; i < scenario.size(); i++) {
// if (Integer.parseInt(scenario.get(counter)[0]) == context.getTimestep()) {
//
// counter = i;
// break;
// }
// }
for (GeoArea geoArea : geoAreas) {
// tagged farm stock
for (Farmer farmer : farmers) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment