I am trying to conditionally switch between compiling the model with one representation vs compiling it with another.
If the condtional is true I can get the model to compile fine. If the conditional is false I get error $2 on the closing $endIf. Examples below:
THE CODE BELOW COMPILES FINE
$setglobal refurbish_version refurbish_akl // ← this will evaluate every $ifThenI to true
sets
map_g_type(g,type) “Map units to their type”
map_g_pool(g,p) “Map units to their pool”
$ifThenI %refurbish_version% == refurbish_akl
valid_refurbish(g,y) “Is it valid for a state that began existing on year y to exist in year y2? Once a state becomes active it cannot become inactive”
$else
valid_refurbish(g,u,y,y2) “Is it valid for a state that began existing on year y to exist in year y2? But once a state becomes active it cannot become inactive”
valid_refurbish_view(g,u,y,y2) “Is it valid for a state that began existing on year y to exist in year y2?”
valid_refurbish_transition(g,u,y,u2,y2) “Is it valid, in year y2, to transition from u->u2 for a state that began existing on year y?”
$endIf
;
<some other code with similar $ifThenI conditionals>
Positive Variables
v_generation, v_capacity, v_base_capacity, v_retrofit_transition, v_obj_cost, v_transmission, v_energy_pool,
v_energy_stored, v_energy_retrieved, v_refurbish_capacity, v_capacity_degradation ,v_refurbish_transition
$ifThenI %refurbish_version% == refurbish_akl
,v_built, v_refurbish, v_reinstate, v_retire_clean, v_retire_degraded, v_postpone
$else // ← If I don’t have this here even though there is no else it throws a compilation error
$endif
;
All of the above works fine.
If however I change the global to something other than refurbish_akl I get the compilation error:
197 $endIf
**** $2
2 Identifier expected
257 Solve statement not checked because of previous errors
299 Unexpected end of file
675 Closing $endif missing
**** 10 ERROR(S) 0 WARNING(S)
Can someone explain what I am doing wrong?
One thing I thought of was maybe the $else can only contain a single statement. So I rewrote the code to be something like below:
$ifThenI %refurbish_version% == refurbish_akl
valid_refurbish(g,y) “Is it valid for a state that began existing on year y to exist in year y2? Once a state becomes active it cannot become inactive”
$else
$endif
$ifThenI NOT %refurbish_version% == refurbish_akl
valid_refurbish(g,u,y,y2) “Is it valid for a state that began existing on year y to exist in year y2? But once a state becomes active it cannot become inactive”
valid_refurbish_view(g,u,y,y2) “Is it valid for a state that began existing on year y to exist in year y2?”
valid_refurbish_transition(g,u,y,u2,y2) “Is it valid, in year y2, to transition from u->u2 for a state that began existing on year y?”
$else
$endIf
This gives me a compile error of:
198 $endIf
**** $2
2 Identifier expected
257 Solve statement not checked because of previous errors
299 Unexpected end of file
675 Closing $endif missing
**** 4 ERROR(S) 0 WARNING(S)
I can get around these problems with gotos, but i’d rather just use if then else endif statements as they seem cleaner.
All help appreciated.
Andrew C