Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
world3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Reuillon
world3
Commits
4bd8544a
Commit
4bd8544a
authored
Nov 15, 2018
by
Julien Perret
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better handling of tables
parent
e9f14a44
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
333 additions
and
250 deletions
+333
-250
plot_script.sh
model/plot_script.sh
+1
-0
Box.scala
model/src/main/scala/world3/Box.scala
+30
-20
World3.scala
model/src/main/scala/world3/World3.scala
+302
-230
No files found.
model/plot_script.sh
View file @
4bd8544a
...
...
@@ -8,6 +8,7 @@ set title \"World3\"
set xlabel
\"
Year
\"
#set size ratio 0.5
#set size 0.5,0.5
set yrange [0:1]
set key outside
plot
\
'/tmp/results.csv' using 1:2 title columnhead(2) w l lw 2 lc rgbcolor
\"
#e07154
\"
,
\
...
...
model/src/main/scala/world3/Box.scala
View file @
4bd8544a
...
...
@@ -259,14 +259,14 @@ object Box {
def
apply
(
qName
:
String
,
qNumber
:
Equation
,
data
:
Vector
[
Double
],
iMin
:
Double
,
iMax
:
Double
,
iDelta
:
Double
,
data
:
Vector
[
(
Double
,
Double
)
],
//
iMin: Double,
//
iMax: Double,
//
iDelta: Double,
updateFn
:
()
=>
Option
[
Double
],
units
:
String
=
"dimensionless"
,
dependencies
:
Vector
[
String
]
=
Vector
())
=
new
Table
(
qName
,
qNumber
,
data
,
iMin
,
iMax
,
iDelta
,
updateFn
,
units
,
dependencies
)
new
Table
(
qName
,
qNumber
,
data
,
/*iMin, iMax, iDelta, */
updateFn
,
units
,
dependencies
)
}
...
...
@@ -274,10 +274,10 @@ object Box {
class
Table
(
val
qName
:
String
,
val
qNumber
:
Equation
,
val
data
:
Vector
[
Double
],
val
iMin
:
Double
,
val
iMax
:
Double
,
val
iDelta
:
Double
,
val
data
:
Vector
[
(
Double
,
Double
)
],
//
val iMin: Double,
//
val iMax: Double,
//
val iDelta: Double,
val
updateFn
:
()
=>
Option
[
Double
],
val
units
:
String
,
val
dependencies
:
Vector
[
String
])
extends
All
{
...
...
@@ -287,23 +287,37 @@ object Box {
var
enabled
=
true
def
interpolate
(
lower
:
Int
,
upper
:
Int
,
fraction
:
Double
)
=
{
val
lowerVal
=
data
(
lower
)
val
upperVal
=
data
(
upper
)
val
lowerVal
=
data
(
lower
)
.
_2
val
upperVal
=
data
(
upper
)
.
_2
lowerVal
+
(
fraction
*
(
upperVal
-
lowerVal
))
}
def
lookup
(
v
:
Double
)
:
Double
=
{
if
(
v
<=
iMin
)
data
(
0
)
else
if
(
v
>=
iMax
)
data
(
data
.
length
-
1
)
// if(v <= iMin) data(0)
// else if(v >= iMax) data(data.length - 1)
// else {
// for ((i, j) <- (BigDecimal(iMin) to iMax by iDelta).zipWithIndex) {
// if(i >= v) {
// // if (qName == "mortality0To14") println(s"$qName lookup ($v) > $j = ${interpolate(j - 1, j, (v - (i - iDelta)) / iDelta)}")
// return interpolate(j - 1, j, (v - (i.toDouble - iDelta)) / iDelta)
// }
// }
// ???
// }
if
(
v
<=
data
.
head
.
_1
)
data
.
head
.
_2
else
if
(
v
>=
data
.
last
.
_1
)
data
.
last
.
_2
else
{
for
((
i
,
j
)
<-
(
BigDecimal
(
iMin
)
to
iMax
by
iDelta
)
.
zipWithIndex
)
{
if
(
i
>=
v
)
{
for
((
i
,
j
)
<-
data
.
zipWithIndex
)
{
if
(
i
.
_1
>=
v
)
{
// if (qName == "mortality0To14") println(s"$qName lookup ($v) > $j = ${interpolate(j - 1, j, (v - (i - iDelta)) / iDelta)}")
return
interpolate
(
j
-
1
,
j
,
(
v
-
(
i
.
toDouble
-
iDelta
))
/
iDelta
)
val
current
=
i
.
_1
val
previous
=
data
(
j
-
1
).
_1
return
interpolate
(
j
-
1
,
j
,
(
v
-
previous
)
/
(
current
-
previous
))
}
}
???
}
}
def
reset
()
=
{}
...
...
@@ -316,8 +330,4 @@ object Box {
def
tick
()
=
{
j
=
k
}
}
}
model/src/main/scala/world3/World3.scala
View file @
4bd8544a
This diff is collapsed.
Click to expand it.
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