0

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.

1 Answer 1

0

.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

Sign up to request clarification or add additional context in comments.

1 Comment

What should I do when someone answers my question? stackoverflow.com/help/someone-answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.