The instance of the class SPARK::TProblem that internally describes the problem under study is actually allocated at runtime from the topology information contained in the *.xml file.
This loading scheme is also referred to as dynamic build. It is the default loading scheme used in the SPARK stand-alone driver. The API functions specific to this loading approach can be found in the namespace SPARK::Problem::DynamicBuild.
sparksolver
(which would be called sparksolver.exe
on a Windows platform), the SPARK usage at the command line with the default driver program is: sparksolver prefFile.prf runFile.run xmlFile.xml <enter>
The API function SPARK::Problem::DynamicBuild::ParseCommandLine() identifies each file name by parsing its extension and returns the name of each file matching the desired extension in the pointers to char
passed as arguments.
char* RunFileName; char* PrfFileName; char* XmlFileName; SPARK::Problem::DynamicBuild::ParseCommandLine( argc-1, // number of entries in argv argv+1, // we skip the first entry which is the full program name RunFileName, // returns full name of *.run file PrfFileName, // returns full name of *.prf file XmlFileName // returns full name of *.xml file );
If any of the three file names with the desired extensions cannot be detected in argv[], the function throws a SPARK::XInitialization exception.
If you write your own customized driver function, you could either specify these files at the command-line (like we do with the default driver function) or have these names hard-coded in the body of the function.
See the example driver function void main()
implemented in the file multiproblem_example1.cpp in the Examples section.
If the API function fails to load the problem, then it returns false. It is good practice to test whether the loading operation failed or not before proceeding. In the next example, we force to exit the simulation if this is the case.
const string XmlFileName("problem.xml"); // name of the *.xml file with the problem description const string ProblemName("My unique problem name"); // unique problem name if ( !SPARK::Problem::DynamicBuild::Load(ProblemName.c_str(), XmlFileName.c_str()) ) { ostringstream ErrMsg; ErrMsg << "Could not load the problem \"" << ProblemName.c_str() << "\" at runtime from " << "the XML description in file \"" << XmlFileName << "\"" << ends; SPARK::ExitWithError( SPARK::ExitCode_ERROR_INVALID_PROBLEM, __FILE__, ErrMsg.str() ); }
One reason why the loading operation might fail is that the required dynamic libraries implementing the atomic classes used in the problem under study cannot be located at runtime. See Build a SPARK problem dynamically.