The SOLVER-AI API provides a set of client classes to facilitate the integration of Python, JavaScript, and C++ with the API. It also provides examples to help you understand how the API works. This document provides a detailed guide on how to use the API.
Note: Browsable API and code are interchangable and can be used together for differnet portions of setup and execution of a Problem.
The clients with its examples can be downloaded from https://github.com/SOLVER-AI-LTD/client.
As first thing, edit the setup/setup.txt file and replace REPLACEWITHSOLVERAITOKENHERE with your token (which you can obtained from Account).
The client folder contains the following sub-folders:
setup Folder
This folder contains the setup.txt file.
cpp, python and js Folders
The cpp, python and js folders contain the client classes:
the examples files which contain the code for the examples presented in this documentation:
the helper code for deleting for cleaning the data on your account:
example_files Folder
This folder contains the data used by the examples.
delete_everything code (USE WITH CAUTION)
The delete_everything code allows deleting all of the Problem and modules.
This code can be used as a starting point for deletin batches of Problems and modules making use of regular expressions based on Problem and module names. It leverages the following member functions of the SolverAiClientSetup class (see below):
C++
The cpp folder contains a Makefile for compileing all of the code with GCC. Compile from within the folder with command
make -f Makefile
SolverAiClientSetup
This class is used to set up the modules (Equation, Code, HardData and SoftData) and then set up a Problem for those modules. It also allows deletion of the modules and Problem as well as a complete cleanup after the solver has run. The class contains the following methods:
IMPORTANT: Remember that modules which have been associated with an existing Problem will not be allowed to be deleted, returning an error for those which have not been deleted.
SolverAiClientCompute
This class is used to run the solver for the problem set up by the SolverAiClientSetup class. It contains the following methods:
inputs
and outputs
, which is a list / array / vector (depending on the programming language) of names of the variables required for setting up the problem.SolverAiComputeInput
This class is used to define the input for the solver, input to function runSolver of an object of class SolverAiClientCompute . It contains the following methods:
inputs
.outputs
as constraint, choosing among the available CONSTRAINT options.outputs
as constraint, choosing among the available OBJECTIVE options.SolverAiComputeResults
This class is used to handle the results from the solver. It contains the following methods:
SolverAiResultsWriter
This class is used for writing the results (SolverAiComputeResults) to a csv file. It contains the following methods:
The examples in the python, js, and cpp folders demonstrate how to use the Client classes. They all perform the same actions, but in different languages. The examples have beed defined so to make them as clear as possible. The examples and data are intentionally extremely simple to help you understand how the SOLVER-AI API works.
Note that although the examples create, execute and delete the problem, this is not required or expected. The modules and Problem could be created via the Browsabel API and the Problem ID simply used in code. Or different codes could perform different operations depending on the work to be performed.
Here are brief descriptions of the examples:
inputs
and outputs
are retrieved and checked.input
for running the solver is prepared.inputs
and outputs
are retrieved and checked.inputs
and outputs
are retrieved and checked.input
for running the solver is prepared.inputs
and outputs
are retrieved and checked.input
for running the solver is prepared.The solver is run as:
results = solverAiClientCompute.runSolver(input)
where input
is of type SolverAiComputeInput and results
is of type SolverAiComputeResults.
As the solver is capable of obtaining one or more solutions (depending on the problem) the data type returned by functions getX and getY of the SolverAiComputeResults will be different depending on the implementation:
std::vector<std::vector<std::variant<std::<float, std::string>>>>
list(list())
Array(Array())
An object results
of type SolverAiComputeResults is such that assuming, getX or getY returned objects X
and Y
, respectively:
X
and Y
would have as many elements as results.getNumberOfResults().X
:X[i]
will be relative to result i.X[i][j]
will contain the value relative to the input variable named inputVariable[j]
, where: inputVariable = results.getInputVariableNames()
Y
:Y[i]
will be relative to result i.Y[i][k]
will contain the value relative to the output variable named outputVariable[k]
, where: outputVariable = results.getOutputVariableNames()