Commit 53ba397c authored by Loris Croce's avatar Loris Croce
Browse files

market dynamics parameters loading

parent ae32b4f5
Pipeline #38201 passed with stages
in 3 minutes and 39 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
......@@ -16,8 +16,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 +27,6 @@ public class MarketDynamics extends Dynamics {
public MarketDynamics() {
initLogger();
assert EXPORT_FACTOR <= 1f;
assert IMPORT_FACTOR <= 1f;
}
@Override
......@@ -53,28 +51,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 +93,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);
}
}
}
......
......@@ -40,6 +40,7 @@ public class PopulationDynamics extends Dynamics {
public PopulationDynamics() {
}
@SuppressWarnings("unchecked")
public void initParameters() {
transitionFile = "transitions.xml";
initLogger();
......
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