Data for Optimization Libaries¶
An AIMMS library can be reused in other projects. To solve an optimization problem in a library we’re dealing with two abstraction mechanisms:
- Procedures where sets transferred via the arguments have different meanings.
- Declare global variables and constraints with a fixed index domain within the library, and use subsets of
AllVariableslocally within that library.
These two abstraction mechanisms do not work together naturally.
This article explains how we can bring these two abstraction mechanisms together using element parameters. We’ll use an example based on the Transport Problem.
The Transport Problem searches for the best way to transport goods from a couple of sources to sinks.
A Transport Problem can be solved locally inside the library.
The following input data is declared in the main model:
This data must be transferred into the library to solve the problem.
Then, the following output data must be transferred back to the main model:
We’ll use the procedure
pr_SolveTransportProblem to complete the transfer in two steps (see image):
- Provide data from
Main Transportto the procedure
pr_SolveTransportProbleminside the library.
- Transfer data from
pr_SolveTransportProblemto the global
These steps are explained in more detail below.
Firstly, the procedure
pr_SolveTransportProblem should contain local arguments. They can be added by pressing the wizard next to arguments. It is important to select the correct type and property of the arguments.
(also something about index)
Now we can call the procedure from the main model. We must provide the input and output arguments in the right order to link them to the local arguments.
Call the procedure as follows:
pl::pr_SolveTransportProblem(s_Sources, s_Sinks, p_Supply, p_Demand, p_TransportCost, p_TotalTransportCost, p_Transport);
Next we’ll transfer the data to the global declaration of the library.
In the main model there is a parameter (
s_Supply) that describes the supply of the sources (
s_Sources). When transferring the data, we must link supplies to the correct sources with element mapping:
1 2 3 4 5
For i_locSo do SetElementAdd(s_libSources, ep_new1, i_locSo); ep_map1(ep_new1) := i_locSo; EndFor; p_libSupply(i_libSo) := p_locSupply( ep_map1(i_libSo));
- line 1:
i_locSois the index of
- line 2: Add the elements to
- line 3: Map the local sources set the library sources set.
- line 5: Link supplies to the right sources.
The rest of the input data is transferred in a similar way.
Then the Transport Problem is calculated and the output data is transferred back like this:
p_locTotalTransportCost := v_libTotalTransportCost; p_locTransport(ep_map1(i_libSo), ep_map2(i_libSi)) := v_libTransport(i_libSo,i_libSi);
Last Updated: July, 2020