BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MikeCarter
Calcite | Level 5

Hi all,

Am pretty new to SAS/OR and to start with, am just trying to solve a simple assignment problem. Three carriers (Carrier 1, Carrier 2, Carrier 3) and three lanes (Lane 1, Lane 2, Lane 3) with their rates. Simple formulation to minimize the cost such that one carrier is assigned one lane and vice-versa. My Data sets are as below. Something is wrong in my coede, not understand what should I do to make it work ?? Please guide !!

DATA

Carrier             Lane         RatePerMile         

Carrier 1Lane 111
Carrier 1Lane 214
Carrier 1Lane 36
Carrier 2Lane 18
Carrier 2Lane 210
Carrier 2Lane 311
Carrier 3Lane 19
Carrier 3Lane 212
Carrier 3Lane 37

DATA1

OneCarrier 1
TwoCarrier 2
ThreeCarrier 3

DATA2

OneLane 1
TwoLane 2
ThreeLane 3

I have introduced binary variable and my code as below-

proc optmodel;

  set <string, string> BIDS;

  number RatePerMile {BIDS} init 0;   /*parameters*/

  Read data Optimize.data

  into BIDS = [Carrier Lane]

  RatePerMile;

  set <string> CARRIERS;

  string CarrierName {CARRIERS};  /*parameters*/

  Read data Optimize.data1

  into CARRIERS = [CarrierID]

  CarrierName;

  set <string> LANES;

  string LaneName {LANES};  /*parameters*/

  Read data OPTIMIZE.DATA2

  into LANES = [LaneID]

  LaneName;

  /*decision variables */

  var Assigned_Truckloads{BIDS} binary;

  /*constraints */

/* 1.. One carrier to One Lane. */

  constraint CarrierToOneLane {ll in LANES}:

  sum{<i,j> in BIDS:(j=ll)} Assigned_Truckloads[i,j] = 1;

/* 2.. One Lane to one carrier.*/

  constraint LaneToOneCarrier {ii in CARRIERS}:

  sum{<i,j> in BIDS:(i=ii) } Assigned_Truckloads[i,j] = 1;

  /*objective function*/

  min Total_Cost =

  sum{<i,j> in BIDS}

  RatePerMile[i,j] * Assigned_Truckloads[i,j];

  solve;

  expand;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
MikeCarter
Calcite | Level 5

Hi Leo,

Thank a bunch for looking into my code. I figured out thatmy CARRIERS and LANES sets had different values (One, Two & Three), whereas the SUM statement was looping over rates data set DATA (Carrier1..Lane1....). Hence it was going infeasible. I took out that CarrierID column (One, Two, Three) and made CarrierName as actual "key index" column contianing actual index values.And it worked.

Sorry for confusion, long story short- I was not reading consisetent data and hence error.

Thanks for your time though,

-Mike


View solution in original post

3 REPLIES 3
LeoLopes
SAS Employee

Hi Mike,

Your code overall looks reasonable. One thing I would do is use a single dataset and derive the LANES and CARRIER sets from BIDS.

You should get more specific answers if you post your log file. Where exactly are you stuck?

MikeCarter
Calcite | Level 5

Hi Leo,

Thank a bunch for looking into my code. I figured out thatmy CARRIERS and LANES sets had different values (One, Two & Three), whereas the SUM statement was looping over rates data set DATA (Carrier1..Lane1....). Hence it was going infeasible. I took out that CarrierID column (One, Two, Three) and made CarrierName as actual "key index" column contianing actual index values.And it worked.

Sorry for confusion, long story short- I was not reading consisetent data and hence error.

Thanks for your time though,

-Mike


LeoLopes
SAS Employee

No problem!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1372 views
  • 0 likes
  • 2 in conversation