BookmarkSubscribeRSS Feed
PatrickYang
Obsidian | Level 7

Our problem is like this:

 

We have 18 bags into which we put items (say products from factory A). We need the weight of each bag to be as close to 25 lbs as possible (Objective function involves an absolute value operation: Minimize   |selected_A[i,j]* weight_A[i] - 25|, for j=1,2,...18 and i is the indiex for items. This objective function needs to be linearized in PROC OPTMODEL which cannot already handle a nonlinear objective function involving integer/binary decision variables). Therefore, we used the following code:

 

set JSET_A = 1..18;

var surplus_A {JSET_A} >= 0;

var slack_A {JSET_A} >= 0;

min objabs_A = sum {j in JSET_A} (surplus_A[j] + slack_A[j]);

con obj_alt_A {j in JSET_A}: sum {i in item_id_set_A} selected_A[i,j]* weight_A[i] – surplus_A[j] + slack_A[j] = 25;

 

As you can see, in the above code regarding the assignment of factory A products to bags, we have created a set of binary decision variables known as selected_A[I,j] indicating whether or not item i from factory A is assigned to bag j with 1 being Yes and 0 being No.

 

Now, we need to fill in a second group of 18 bags using products from factory B. Also, we need to worry about the weight of each bag. We would like the weight of each bag to be as close to 30 lbs as possible. Therefore, we have set up our analysis in a way similar to the above one, only changing the index subscript from A to B:

 

set JSET_B = 1..18;

var surplus_B {JSET_B} >= 0;

var slack_B {JSET_B} >= 0;

min objabs_B = sum {j in JSET_B} (surplus_B[j] + slack_B[j]);

con obj_alt_B {j in JSET_B}: sum {i in item_id_set_B} selected_B[i,j]* weight_B[i] – surplus_B[j] + slack_B[j] = 30;

 

Obviously, the first analysis is based on one data set containing the weight information of items from factory A whereas the second analysis is based on a second, different data set containing the weight information of items from factory B (i.e., two different date sets are involved in this analysis). Also note that products from the same factory are allowed to be different in weight.

 

With both groups of 18 bags filled up, we need to create a gift packet by pulling one bag randomly from the first 18 bags and a second bag randomly from the second 18 bags. Here, we need to create a constraint which requires the sum of the number of items from the first bag containing factory A products and the number of items from the second bag containing factory B products should be greater than or equal to 3. In other words, we would like a constraint like the following one:

sum {i in item_id_set_A} selected_A[i,j]+ sum {i in item_id_set_B} selected_B[i,j]>=3;

 

As you can see, this proposed constraint above involves multiple data sets. I am wondering if it is technically possible to create such a constraint in SAS PROC OPTMODEL? If possible, how (using multiple sub-problems or something else)?

 

Thank you so much!

3 REPLIES 3
RobPratt
SAS Super FREQ

It seems like maybe you are missing a constraint that each item is assigned to exactly one bag.

 

con assign_A {i in item_id_set_A}: sum {j in JSET_A} selected_A[i,j] = 1;

 

And a similar constraint for B.

 

In any case, there is nothing preventing you from declaring constraints that involve both selected_A and selected_B.  But if you want to solve one optimization problem, you should then declare a single objective function, perhaps just the sum of your two objective functions:

 

min objabs = objabs_A + objabs_B;

PatrickYang
Obsidian | Level 7

Hi Rob:

 

Thank you for your reply and the reminder regarding the additional contraint. In fact, we have more product items than we need so that we set up our constraint as <=1. That is, each produt item is used once or less:

con assign_A {i in item_id_set_A}: sum {j in JSET_A} selected_A[i,j] <= 1;

and

con assign_B {i in item_id_set_B}: sum {j in JSET_B} selected_B[i,j] <= 1;

 

Here, I am wondering about the summation of two objective functions that you are proposing. As far as I know, SAS PROC OPTMODEL allows multiple objective functions, which is a very nice feature. However, it has to be that one is optimized first before a second one is handled. When you create a summation of two objective fuctions to produce a third objective function, does it mean the optimization of the summation in fact simultaneously optimizes its composing two objective functions?

 

I am asking because it appears that, under the situation of one function being optimized first before another one is handled, the ordering of objective functions matters. That is, A optimized ahead of B may be different than B optimized ahead of A. If A and B can be simultaneously optimized, that would appear to be a new, third situation.

RobPratt
SAS Super FREQ

The solver optimizes only one objective.  By default, it uses the objective that was declared last.  But you can also specify an objective by using the OBJECTIVE keyword in the SOLVE statement:

http://support.sas.com/documentation/cdl/en/ormpug/68156/HTML/default/viewer.htm#ormpug_optmodel_syn...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 900 views
  • 0 likes
  • 2 in conversation