Reputation: 1
I am developing an optimization model in OPL where one of the parameters average of decision variable for the objective function mathematical expression of objective function is fed from Python in tuple form. The objective function minimizes the squared difference between decision variables and externally provided averages.
I use the doopl library to solve the optimization model in Python. Since the data is passed from Python to OPL in tuple form, I structure of the input to match the format of the OPL model and the code for the objective function in OPL model is given below.
The code that I am trying in OPL is given below:
// Decision variable
dvar float+ x_meg[MEG];
// Tuple passed from Python containing the average values
tuple AverageMEG {
int id; // ID for MEG
float average; // Average value for MEG
};
{AverageMEG} average_meg = ...; // Input from Python
// Objective function
minimize
sum(k in MEG, avg in average_meg: avg.id == k)
(x_meg[k] - avg.average)^2;
Could you please confirm whether the objective function code mentioned above is written correctly? I'm particularly interested in verifying if the current approach to coding the objective function, as structured with input data from Python in tuple form, is accurate. Your feedback on this implementation would be appreciated.
Upvotes: 0
Views: 25
Reputation: 10062
.mod
range MEG=1..4;
// Decision variable
dvar float+ x_meg[MEG];
// Tuple passed from Python containing the average values
tuple AverageMEG {
int id; // ID for MEG
float average; // Average value for MEG
};
{AverageMEG} average_meg = ...; // Input from Python
// Objective function
minimize
sum(k in MEG, avg in average_meg: avg.id == k)
(x_meg[k] - avg.average)^2;
.dat
average_meg={<2,5>};
work fine and average_meg is a tuple set so this is ok with doopl
Upvotes: 0