StartGame: not able to start from beginning

Hi,
i’m trying to replay a run, and in doing so, changing a game variable to influence the outcome.
As i understand, you can only change a game variable, at the current step. So, i want to start from the beginning, and loop through the steps, while setting the game variable from an input array.

The variable is flagged GAME in the vensim model, and in retrospective flagged as ALLWAYS. The problem i believe, is that the run does not start from Step 1.
i do a : https://api.forio.com/v2/run/dn/test3/000001718dd7ac830e889f82167467bc68db/operations/startGame
but when i ask for the current step right after this with:
https://api.forio.com/v2/run/dn/test3/000001718dd7ac830e889f82167467bc68db/variables/Step
result: 99
(time is from 0 to 99)
whatever i do, i do not seem able to get the current step to 0 or 1, to start the loop for setting the game variables…

do you have any clues?

much appreciated,
grtz
Wim

Hi Wim,

This works fine for me. Here’s the API calls I did. Obviously, you’ll need to change the run id and add appropriate authorization headers.

Start the run
POST https://api.forio.com/v2/run/dn/test3
body: {"model":"model_poc_001_work_001.vmfx"}

Note – Time is 1
GET https://api.forio.com/v2/run/dn/test3/00000171e08a8a4883bac53080f93bd2484b/variables?include=Time

result:

{
    "Time": [
        1.0
    ]
}

This is an archaic call. It’s not actually required any more
POST https://api.forio.com/v2/run/dn/test3/00000171e08a8a4883bac53080f93bd2484b/operations/startGame
body: {}

Time is still 1
GET https://api.forio.com/v2/run/dn/test3/00000171e08a8a4883bac53080f93bd2484b/variables?include=Time

result:

{
    "Time": [
        1.0
    ]
}

Step the sim one time unit
POST https://api.forio.com/v2/run/dn/test3/00000171e08a8a4883bac53080f93bd2484b/operations/step
body: {}

returns the new step of 2

{
    "result": 2.0,
    "name": "step"
}

Time is now 2
GET https://api.forio.com/v2/run/dn/test3/00000171e08a8a4883bac53080f93bd2484b/variables?include=Time

{
    "Time": [
        1.0,
        2.0
    ]
}

many thx Will !, i got it working - or moving at least :slight_smile: .
tried it with a new runid

i think the cause lays in my misconception of ‘startGame’. this does not reset the step to 1 apparently ? so once run, the startGame didn’t reset my step.

but a ‘reset’ operation on the runid does. So i tried it with a reset and now it works.
still i must be missing something. resetting the run, and playing/setting the same values on the game variables, results in different outcomes…
how is this possible?
or should i just create a new run for each scenario (=different set of game variables), that I want to run?
(and then delete the run)
thx
Wim

Hi –

startGame is an archaic operation. It used to be required in order to initiate the Vensim model from an “off” state to step 0. It was ignored otherwise. But now we just initialize the Vensim model when the run starts. (If you set constants in period 0, it re-initializes the model and reapplies the inputs).

Unless you are doing a “turn by turn” game, you need to start a new run for each set of new variables. In a turn by turn game you’d reset once you reach the end of the time range.

The Javascript libraries have an operation “reset”, but this isn’t actually passed to the web service apis. Instead it just forgets the current run and starts a new one.

WILL

thx Will, changed it run create run everytime,
works perfect,
but how would you explain the different result output? (after the last step i retrieve
https://api.forio.com/v2/run/dn/test3/runId/variables?include=Average number of Rentalmachines returned

although i use the same input set (i chked the log), i get a different array of output

i’m lost here

thx

Is there randomness in your sim? If not it should return the same thing.

I notice that you moved to a new model in your account. Note that the new model is not picked up in the current run but is used the next time a run is started. (or the original run times out and is replayed).

no, nothing random. i create new and simplified the model ( forio.com/app/dn/work_002, but still strange random outputs,

and sometimes, i get the same results as my vensim game (without changing anything), does not compute… :frowning:

is this the correct way to patch a variable in the current step ? i patch it, and then step forward.
https://api.forio.com/v2/run/dn/test3/0000017154b51e74fb1d9f5530aa0e327875/variables
{“Average number of Rentalmachines returned”: 1250}

or do i need to update it as a specific element in the array with current step as index or something?
like this {“Average number of Rentalmachines returned[]”: 1250}

each time i run, i create a completely new run. i don’t understand where the random factor is coming from,
all help much appreciated,
grtz
Wim

Hi Wim,

It’s consistent for me. Note that your examples had curly quotes, not regular quotes. (Might be due to the forum software).

When I

  • create a new run
  • patch the variable to 1250
  • step
  • get the variable

It returns an array for the variable over time:

{
    "Average number of Rentalmachines returned": [
        1250.0,
        1250.0
    ]
}

Here’s the specific calls. I used PostMan to test. Note you should not provide empty subscripts in the Patch as in your example.

POST https://api.forio.com/v2/run/dn/work_002
body: {"model":"model_poc_001_work_002.vmfx"}

PATCH https://api.forio.com/v2/run/dn/work_002/00000171ea1523b37726ba95ffdd1c4a96eb/variables
body: {"Average number of Rentalmachines returned": 1250}

POST https://api.forio.com/v2/run/dn/work_002/00000171ea1523b37726ba95ffdd1c4a96eb/operations/step
body: {}

GET https://api.forio.com/v2/run/dn/work_002/00000171ea1523b37726ba95ffdd1c4a96eb/variables?include=Average number of Rentalmachines returned

which returns

{
    "Average number of Rentalmachines returned": [
        1250.0,
        1250.0
    ]
}

found it Will,
omg : root cause was the processing of de calls in azure logic app. i simulated it with postman (thx - you forced me to back to basics) and there it worked.
in azure logic app, loop actions (to set my game variable), are processed simultaneously by default :frowning:
this was the cause for the random behavior ofcourse…

thx for your endurance to help me!
grtz
Wim