Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct code generation for cases involving multiple dimensions that resolve to same family #588

Merged
merged 26 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
59dad5e
test: add test model that reproduces bug with multi-dimensional varia…
chrispcampbell May 3, 2022
d697277
Merge branch 'main' into chris/179-multi-dim-with-alias
chrispcampbell Oct 28, 2022
9fae0bd
test: add more tests for subscripted equations
chrispcampbell Oct 30, 2024
8a1f991
fix: remove normalizeSubscripts and always keep LHS in the original o…
chrispcampbell Nov 3, 2024
4e22955
refactor: change variable names to include "rhs" for clarity + add ex…
chrispcampbell Nov 23, 2024
847d928
test: add tests that cover the same {0,1,2,3}D cases in read-equation…
chrispcampbell Nov 23, 2024
be8e068
Merge branch 'main' into chris/179-multi-dim
chrispcampbell Nov 24, 2024
3d6e19f
test: add tests that exercise mapped subscripts + fix expected values…
chrispcampbell Nov 25, 2024
e99215a
fix: mark generated aux variables as non-apply-to-all in separated DE…
chrispcampbell Nov 25, 2024
58a7201
fix: define refIds for all generated variables before calling readEqu…
chrispcampbell Nov 25, 2024
c2ed48f
test: unskip test that no longer fails after the fixes to expandedRef…
chrispcampbell Nov 25, 2024
65f21a6
fix: reimplement expandedRefIdsForVar to better handle cases where mu…
chrispcampbell Nov 25, 2024
e5b9f24
fix: update comment
chrispcampbell Nov 25, 2024
65f1b61
test: simplify comments in tests that show the expected behavior of e…
chrispcampbell Nov 25, 2024
79a5d44
fix: pre-allocate loop index variables according to the order of LHS …
chrispcampbell Nov 25, 2024
dfca85e
refactor: move loop body into new resolveRhsSubOrDim function
chrispcampbell Nov 26, 2024
7b3f993
fix: reimplement cVarRef to better handle cases where multiple dimens…
chrispcampbell Nov 26, 2024
6e5b70f
fix: remove obsolete code related to marked dims now that they are ha…
chrispcampbell Nov 28, 2024
104a722
Merge branch 'chris/179-multi-dim-with-alias' into chris/179-multi-dim
chrispcampbell Dec 3, 2024
bf2582a
test: rename sample model from 179
chrispcampbell Dec 4, 2024
17539b0
test: remove outputVarNames for arrays sample model so that all varia…
chrispcampbell Dec 4, 2024
0a1feb0
test: add sample model from 278
chrispcampbell Dec 4, 2024
d2c5b28
test: update sum sample model to include the cases from issue 85
chrispcampbell Dec 4, 2024
bc1a2ce
Merge branch 'main' into chris/179-multi-dim
chrispcampbell Dec 8, 2024
1d6861e
test: add more tests for handling of marked dimensions including the …
chrispcampbell Dec 8, 2024
2ccee4b
Merge branch 'main' into chris/179-multi-dim
chrispcampbell Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions models/arrays/arrays_spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "Arrays test model (where the spec file contains Vensim variable names)",
"inputVarNames": ["inputA[A1]", "inputA[A2]", "inputA[A3]"],
"outputVarNames": ["Time", "a[A1]", "a[A2]", "a[A3]", "f[A1,B1]", "f[A1,B2]", "f[A1,B3]", "h", "ndim4[A3,B3,C3,D4]"]
"name": "Arrays test model",
"inputVarNames": ["inputA[A1]", "inputA[A2]", "inputA[A3]"]
}
132 changes: 132 additions & 0 deletions models/same_family_179/same_family_179.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
FINAL TIME
0 1
Fractional Increase[A1,A1]
0 0
1 0
Fractional Increase[A1,A2]
0 1
1 1
Fractional Increase[A1,A3]
0 1
1 1
Fractional Increase[A2,A1]
0 0
1 0
Fractional Increase[A2,A2]
0 1
1 1
Fractional Increase[A2,A3]
0 0
1 0
Fractional Increase[A3,A1]
0 0
1 0
Fractional Increase[A3,A2]
0 0
1 0
Fractional Increase[A3,A3]
0 1
1 1
INITIAL TIME
0 0
Intensity[A1]
0 1000
Intensity[A2]
0 1000
Intensity[A3]
0 1000
Intensity[B1]
0 1000
Intensity[B2]
0 1000
Intensity[B3]
0 1000
Intensity Diff[A1,A1]
0 990
1 990
Intensity Diff[A1,A2]
0 666
1 666
Intensity Diff[A1,A3]
0 666
1 666
Intensity Diff[A2,A1]
0 990
1 990
Intensity Diff[A2,A2]
0 600
1 600
Intensity Diff[A2,A3]
0 666
1 666
Intensity Diff[A3,A1]
0 990
1 990
Intensity Diff[A3,A2]
0 600
1 600
Intensity Diff[A3,A3]
0 100
1 100
Intensity Diff[B1,B1]
0 990
1 990
Intensity Diff[B1,B2]
0 777
1 777
Intensity Diff[B1,B3]
0 777
1 777
Intensity Diff[B2,B1]
0 990
1 990
Intensity Diff[B2,B2]
0 600
1 600
Intensity Diff[B2,B3]
0 777
1 777
Intensity Diff[B3,B1]
0 990
1 990
Intensity Diff[B3,B2]
0 600
1 600
Intensity Diff[B3,B3]
0 100
1 100
Other[A1]
0 10
Other[A2]
0 400
Other[A3]
0 900
Other[B1]
0 10
Other[B2]
0 400
Other[B3]
0 900
Rank[A1]
0 1
Rank[A2]
0 2
Rank[A3]
0 3
Rank[B1]
0 1
Rank[B2]
0 2
Rank[B3]
0 3
SAVEPER
0 1
1 1
Something[A1]
0 100
Something[A2]
0 200
Something[A3]
0 300
TIME STEP
0 1
59 changes: 59 additions & 0 deletions models/same_family_179/same_family_179.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{UTF-8}

DimA: A1, A2, A3
~~|
DimA' <-> DimA
~~|

DimB: B1, B2, B3
~~|
DimB' <-> DimB
~~|

DimAB1: A1, B1
~~|
DimAB2: A2, B2
~~|
DimAB3: A3, B3
~~|

DimAB: DimAB1, DimAB2, DimAB3
~~|

DimABC: A1, A2, A3, B1, B2, B3, C1, C2, C3
~~|

Rank[DimA] = 1, 2, 3
~~|
Rank[DimB] = 1, 2, 3
~~|

Intensity[DimAB] = 1000 ~~|

Something[A1] = 100 ~~|
Something[A2] = 200 ~~|
Something[A3] = 300 ~~|

Other[DimAB1] = 10 ~~|
Other[DimAB2] = INITIAL ( Something[A2] * 2 ) ~~|
Other[DimAB3] = INITIAL ( Something[A3] * 3 ) ~~|

Intensity Diff[DimA,DimA'] =
IF THEN ELSE (
Rank[DimA] >= Rank[DimA'] ,
ABS ( Intensity[DimA] - Other[DimA'] ),
666
)
~~|
Intensity Diff[DimB,DimB'] =
IF THEN ELSE (
Rank[DimB] >= Rank[DimB'] ,
ABS ( Intensity[DimB] - Other[DimB'] ),
777
)
~~|

INITIAL TIME = 0 ~~|
FINAL TIME = 1 ~~|
TIME STEP = 1 ~~|
SAVEPER = TIME STEP ~~|
67 changes: 67 additions & 0 deletions models/same_family_278/same_family_278.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
FINAL TIME
0 1
INITIAL TIME
0 0
SAVEPER
0 1
1 1
TIME STEP
0 1
U[A1,A1]
0 106
1 106
U[A1,A2]
0 107
1 107
U[A2,A1]
0 206
1 206
U[A2,A2]
0 207
1 207
V[S1,A1,A1]
0 1101
1 1101
V[S1,A1,A2]
0 1102
1 1102
V[S1,A2,A1]
0 1201
1 1201
V[S1,A2,A2]
0 1202
1 1202
V[S2,A1,A1]
0 2101
1 2101
V[S2,A1,A2]
0 2102
1 2102
V[S2,A2,A1]
0 2201
1 2201
V[S2,A2,A2]
0 2202
1 2202
X[A1,A1]
0 101
X[A1,A2]
0 102
X[A1,A3]
0 103
X[A2,A1]
0 201
X[A2,A2]
0 202
X[A2,A3]
0 203
X[A3,A1]
0 301
X[A3,A2]
0 302
X[A3,A3]
0 303
Y[S1]
0 1000
Y[S2]
0 2000
47 changes: 47 additions & 0 deletions models/same_family_278/same_family_278.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{UTF-8}

Scenario : S1, S2
~~|

Sector : A1, A2, A3
~~|

Supplying Sector : A1, A2
-> Producing Sector
~~|

Producing Sector : A1, A2
-> Supplying Sector
~~|

X[A1,A1] = 101 ~~|
X[A1,A2] = 102 ~~|
X[A1,A3] = 103 ~~|
X[A2,A1] = 201 ~~|
X[A2,A2] = 202 ~~|
X[A2,A3] = 203 ~~|
X[A3,A1] = 301 ~~|
X[A3,A2] = 302 ~~|
X[A3,A3] = 303 ~~|

Y[S1] = 1000 ~~|
Y[S2] = 2000 ~~|

U[Supplying Sector, Producing Sector] =
X[Supplying Sector, Producing Sector] + 5
~
~
~ :SUPPLEMENTARY
|

V[Scenario, Supplying Sector, Producing Sector] =
Y[Scenario] + X[Supplying Sector, Producing Sector]
~
~
~ :SUPPLEMENTARY
|

INITIAL TIME = 0 ~~|
FINAL TIME = 1 ~~|
TIME STEP = 1 ~~|
SAVEPER = TIME STEP ~~|
Loading