Convert Modgen models and usage of cpp - openmpp/openmpp.github.io GitHub Wiki
It may be your model is using microdata files or it contains references
to Modgen global variables: gpoEventQueue, gbCanceled, gbErrors
or functions: StartCase(), SignalCase()
. For example if your Modgen code look like:
// The Simulation function is called by Modgen to simulate a set of cases.
void Simulation()
{
// Open the microdata file
PersonOpenFile();
// The global variables gbInterrupted, gbCancelled and gbErrors
// are maintained by the Modgen run-time.
for (long lCase = 0; lCase < CASES() && !gbInterrupted && !gbCancelled && !gbErrors; lCase++ )
{
// Simulate a case.
// Tell the Modgen run-time to prepare to simulate a new case.
StartCase();
// Read the record corresponding to the case_id of the case
long lCaseID = GetCaseID();
PersonGetRecord(lCaseID);
// Call the CaseSimulation function defined earlier in this module.
CaseSimulation();
// Tell the Modgen run-time that the case has been completed.
SignalCase();
}
// Close the microdata file
PersonCloseFile();
}
// The CaseSimulation function simulates a single case
void CaseSimulation( )
{
// ...................
// Process events until there are no more
ProcessEvents();
// ...................
}
// The ProcessEvents function processes all events until there are none in the event queue.
// It is called by the CaseSimulation function.
void ProcessEvents()
// The Modgen run-time implements the global event queue gpoEventQueue.
while ( !gpoEventQueue->Empty() )
{
// The global variables gbCancelled and gbErrors
// are maintained by the Modgen run-time.
if ( gbCancelled || gbErrors )
{
// The user cancelled the simulation, or run-time errors occurred.
// Terminate the case immediately.
gpoEventQueue->FinishAllActors();
}
else
{
// Age all actors to the time of the next event.
gpoEventQueue->WaitUntil( gpoEventQueue->NextEvent() );
// Implement the next event.
gpoEventQueue->Implement();
}
}
}
Then please use OzProj example model to update your CaseSimulation() function.
There are Modgen version of code_original\OzProj.mpp
and openM++ version: code\OzProj.mpp
which you can use as starting point to upgrade your model code.
Use of ternary operator may require cast to underlying type (type name followed by _t
).
The Microsoft VC++ error number is a strong hint. The error message text is not helpful.
Assignments from one attribute to another may require cast to underlying type. Specific Microsoft VC++ error number helps to indicate the occurrence (the error message text is not helpful).
Use of min and max may need to be changed to specify the underlying type.
We would recommend to invoke the template explicitly, eg std::max<double>(a, b)
Non-standard Microsoft functions and types must be replaced with standard. It is easy to detect such error: build your model on MacOS or Linux and to detect all non-standard Microsoft extensions.