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