I have a 4x3 matrix with numbers from 0 to 10 and I want to convert it to a 4x3 matrix with binary numbers, so any number >=1 in the original matrix becomes a 1, and all 0's stay as 0 in the new matrix. I have managed to make it work in Excel by two different ways: a simple way using the IF function (I had to change the Solver method) and more complex way calculating the Lane pairs combinations and doing some arithmetics with them, something logically and unfortunately only valid for this specific example (so kind of useless). In SAS, with a 4x1 matrix I was able to do it by using a linking constraint. Quick example: proc optmodel; set DC={1..4}; set Customer={1..3}; number demand{Customer}=[20 30 40]; number varcost{DC, Customer} = [ 200 100 300 100 200 300 300 200 100 200 300 100]; number fixcost{DC} = [200 100 300 400]; number Pmax = 2; var open{DC} binary; var flow{DC, Customer} >= 0; min totalcost= sum{i in DC, j in Customer}flow[i,j]*varcost[i,j] + sum{i in DC}fixcost[i]*open[i]; con demandcon{j in Customer}: sum{i in DC}flow[i,j] = demand[j]; con linkingcon{i in DC, j in Customer}: flow[i,j] <= 99999*open[i]; con maxcon: sum{i in DC}open[i] <= Pmax; solve; print flow totalcost open; Those numbers where the sum{i in DC}flow[i,j] >0 will be forced to become 1, and for those <=0 the optimization will choose to make them become 0 in the OPEN 4x1 binary matrix since I am minimising and each 1 in the OPEN variable would add a fixcost to the totalcost function. This method allow me also to specify the maximum number of DC to use thanks to the Pmax (or the minimum with an additional constraint). However, now I am dealing with a 4x3 matrix and my linking constraint doesn't seem to work since the model can now assign the 0's to any other column of the matrix when I specify a Pmax or a Pmin. More complex example: proc optmodel printlevel=0;
set Carrier={'I','II','III'};
set Lane={'A','B','C','D'};
set Pack={1..15};
number Bids{Carrier,Pack}=[
489 433 464 467 846 712 748 741 758 823 1112 1199 1056 1672 1872
427 446 494 452 708 758 748 712 734 714 1039 1199 1112 1693 1873
407 495 414 472 829 832 752 803 771 736 1041 1166 1073 1560 1780];
number PackBin{Lane,Pack}=[
1 0 0 0 1 1 1 0 0 0 1 1 1 0 1
0 1 0 0 1 0 0 1 1 0 1 1 0 1 1
0 0 1 0 0 1 0 1 0 1 1 0 1 1 1
0 0 0 1 0 0 1 0 1 1 0 1 1 1 1];
number DemandLane{Lane}=[12 10 14 11];
number TotalDemand = sum{j in Lane}DemandLane[j];
number MinCarrierPerLane = 2;
number MaxCarrierPerLane = 3;
number uselinecost{Lane,Carrier}=[
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999];
var Loads{Carrier,Pack} integer >=0 ;
var Usecarrier{Lane,Carrier} binary;
min Z=sum{i in Carrier, k in Pack}Bids[i,k]*Loads[i,k]+sum{j in Lane,i in Carrier}uselinecost[j,i]*usecarrier[j,i];
* The following constraint does not affect the result. I use it to print the Real Cost;
con Real_Cost: sum{i in Carrier, k in Pack}Bids[i,k]*Loads[i,k]>=0;
con DemandPerLaneCon{j in Lane}: sum{i in Carrier, k in Pack}PackBin[j,k]*Loads[i,k]=DemandLane[j];
con linkingcon{j in Lane, i in Carrier}: sum{k in Pack}PackBin[j,k]*Loads[i,k]<= TotalDemand*usecarrier[j,i];
* The following constraint does not affect the result. I use it to print the Lanes per Carrier;
con cons1{j in Lane, i in Carrier}: sum{k in Pack}PackBin[j,k]*Loads[i,k]>=0;
con MinCarrierPerLaneCon{j in Lane}: sum{i in Carrier}Usecarrier[j,i] >= MinCarrierPerLane;
con MaxCarrierPerLaneCon{j in Lane}: sum{i in Carrier}Usecarrier[j,i] <= MaxCarrierPerLane;
solve;
print TotalDemand Z Real_Cost.body Usecarrier Loads cons1.body;
quit; The MinCarrierPerLane is set to 2, and the linking constraint seems to fail to convert the 4x3 matrix (cons1.body) into a binary 4x3 matrix where 0's remain 0 and numbers >0 become 1: result Obviously it seems that my linking constraint is incomplete in some way, but I have not been able to find out where or why for 2 days. Any hints?
... View more