Commit 2ffbd33f authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

Merge origin/master

parents d1f67ce0 c89720de
Pipeline #38275 passed with stages
in 3 minutes and 57 seconds
0, minimal, 0.5, 0.7
365, minimal, 0.5, 0.7
730, minimal, 0.5, 0.7
\ No newline at end of file
0,minimal,0.3, 0.7
365,minimal,0.8, 0.2
730,minimal,0.5, 0.9
1095,minimal,0.1, 0.6
\ No newline at end of file
......@@ -5,7 +5,6 @@ public class Patch {
private transient Farm farm;
private GeoArea geoArea;
private Float surface;
//TODO correspondig tag production and practice
private CulturalPractice practice;
private Production production;
private Float yield;
......
......@@ -15,9 +15,8 @@ import java.util.stream.Collectors;
public class MarketDynamics extends Dynamics {
// TODO make it in/out parameters by geoArea/product
private float EXPORT_FACTOR;
private float IMPORT_FACTOR;
private float exportFactor;
private float importFactor;
private Stocks localExchanged = new Stocks();
private Stocks importation = new Stocks();
private Stocks exportation = new Stocks();
......@@ -27,8 +26,6 @@ public class MarketDynamics extends Dynamics {
public MarketDynamics() {
initLogger();
assert EXPORT_FACTOR <= 1f;
assert IMPORT_FACTOR <= 1f;
}
@Override
......@@ -38,7 +35,6 @@ 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) {
......@@ -53,28 +49,37 @@ public class MarketDynamics extends Dynamics {
@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;
// }
// }
// default values
exportFactor = 1;
importFactor = 1;
for (GeoArea geoArea : geoAreas) {
// selecting import/export factors from scenario
for (int i = counter; i < scenario.size(); i++) {
if (Integer.parseInt(scenario.get(i)[0]) == context.getTimestep()) {
if (scenario.get(i)[1] == geoArea.getLabel()) {
importFactor = Float.parseFloat(scenario.get(i)[2]);
exportFactor = Float.parseFloat(scenario.get(i)[3]);
assert importFactor <= 1;
assert exportFactor <= 1;
counter++;
break;
}
}
}
// tagged farm stock
for (Farmer farmer : farmers) {
matchingTagAllocationProduction(farmer.getFarm().getProductions(), geoArea.getFlows());
globalExport(farmer.getFarm().getProductions(), global);
globalExport(farmer.getFarm().getProductions(), global, exportFactor);
}
// tagged flow stock
for (Flow flow : geoArea.getFlows()) {
matchingTagAllocationProduction(flow.getQuantities(), geoArea.getFlows().stream()
.filter(e -> !geoArea.getFlows().contains(flow))
.collect(Collectors.toList()));
globalImport(flow, global);
globalExport(flow.getQuantities(), global);
globalImport(flow, global, importFactor);
globalExport(flow.getQuantities(), global, exportFactor);
}
logger.logQuantities(context.getTimestep(), geoArea, localExchanged, "local");
logger.logQuantities(context.getTimestep(), geoArea, importation, "import");
......@@ -86,24 +91,24 @@ public class MarketDynamics extends Dynamics {
}
}
public void globalImport(Flow flow, Flow global) {
public void globalImport(Flow flow, Flow global, Float importFactor) {
for (Map.Entry<Product, Float> production : global.getQuantities().entrySet()) {
for (Input input : flow.getInputs()) {
if (input.getProduct().equals(production.getKey())) {
if (input.getProduct().getTags().equals(production.getKey().getTags())) {
allocate(production, input, flow, importation, IMPORT_FACTOR);
allocate(production, input, flow, importation, importFactor);
}
}
}
}
}
public void globalExport(Stocks stocks, Flow global) {
public void globalExport(Stocks stocks, Flow global, Float exportFactor) {
for (Map.Entry<Product, Float> production : stocks.entrySet()) {
for (Input input : global.getInputs()) {
if (input.getProduct().equals(production.getKey()))
if (input.getProduct().getTags().equals(production)) {
allocate(production, input, global, exportation, EXPORT_FACTOR);
allocate(production, input, global, exportation, exportFactor);
}
}
}
......@@ -120,7 +125,7 @@ public class MarketDynamics extends Dynamics {
for (Map.Entry<Product, Float> production : productions.entrySet()) {
for (Flow flow : flows) {
for (Input input : flow.getInputs()) {
// products match TODO check equals behaviour for tags
// products match
if (input.getProduct().equals(production.getKey())) {
// check all tags
if (input.getProduct().getTags().equals(production.getKey().getTags())) {
......
......@@ -40,6 +40,7 @@ public class PopulationDynamics extends Dynamics {
public PopulationDynamics() {
}
@SuppressWarnings("unchecked")
public void initParameters() {
transitionFile = "transitions.xml";
initLogger();
......
Supports Markdown
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