Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Agriterix
simulator
Commits
53ba397c
Commit
53ba397c
authored
Jul 26, 2021
by
Loris Croce
Browse files
market dynamics parameters loading
parent
ae32b4f5
Pipeline
#38201
passed with stages
in 3 minutes and 39 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
data/in/config/import_export.csv
View file @
53ba397c
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
src/main/java/fr/inrae/agriterix/simulator/dynamics/MarketDynamics.java
View file @
53ba397c
...
...
@@ -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
<=
1
f
;
assert
IMPORT_FACTOR
<=
1
f
;
}
@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
);
}
}
}
...
...
src/main/java/fr/inrae/agriterix/simulator/dynamics/PopulationDynamics.java
View file @
53ba397c
...
...
@@ -40,6 +40,7 @@ public class PopulationDynamics extends Dynamics {
public
PopulationDynamics
()
{
}
@SuppressWarnings
(
"unchecked"
)
public
void
initParameters
()
{
transitionFile
=
"transitions.xml"
;
initLogger
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment