0

CPLEX; Mixed Integer Linear Programming; Constraint Formulation:

There are 150 towns in the dataset, each town having several markets (or "mandis"). Total number of mandis in the dataset = 1800. I have a binary decision variable y[mandi][days]. I want to add a constraint which states that y[mandi][days] is equal for all mandis within any given town on any given day. y[mandi][days] could be different/same for the mandis in different towns on the same day.

Sample Data

I'm inputting the data from Excel. Please see the attached image. Can you help me out with how to formulate this constraint in OPL?

One way to achieve the above is to specify individual constraints on the set of mandis within each town. However, the number of constraints, in that case, would become 150, each referring to one town. Also, we might receive from the client an additional list of mandis for some towns, which would distort the mandi-town mapping numbering, and I would have to change the mapping in CPLEX again. Is there a better way to do this, which could take the mapping directly from excel in the attached image format?

Aman Kabra
  • 31
  • 5

1 Answers1

0

Instead of the decision variable

dvar boolean y[mandi][days]

why not use

dvar boolean y[town][days]

?

And then when you need the y for a given mandi, you first get the town of that mandi and then get its y.

halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Alex, thanks for responding! I'm unable to create a mapping between town and mandis within CPLEX. That's the problem. The mapping is present in the Excel file as shared in the screenshot. How do I read the mapping from excel file and then write that constraint? – Aman Kabra Jul 13 '20 at 09:25
  • I sense there is a gap in my explanation. The required output is y[mandis][days]. This is a binary 1800*61 matrix. (The number of days is 61). Now, the constraint is to enforce all mandis within any given town to have the same y for any given day. Basically, y[i][t] == y[j][t] ∀ i,j ∈ w, ∀w (where w is any given town). – Aman Kabra Jul 13 '20 at 09:36
  • Note: y[town][days] doesn't make sense from a physical perspective, and other constraints are run on mandis. We can have y[i][t] for mandis and not towns. In my problem statement, y represents whether a mandi is open or not. All mandis in the same town are supposed to be open on same days. Hope this clarifies the question. – Aman Kabra Jul 13 '20 at 09:42
  • y[town][days] is better. But if you want to keep y[mandi][days] you could write something like forall(d in days, ordered m1,m2 in mandi:m1.town==m2.town) y[m1][d]==y[m2][d] – Alex Fleischer Jul 13 '20 at 09:52
  • I agree with Alex - if there are sets of mandis (e.g. all the mandis in a town) that are open or closed together, then it would be better to have one variable that is shared by all the mandis in the town. It can still look like there is a variable for each mandi, but use something like y[mandi.town][day]. Otherwise you are giving the solver a lot of excess work to do. Getting the structure of the model right is the most important thing, then the rest is just 'normal' programming to implement that model correctly. – TimChippingtonDerrick Jul 14 '20 at 06:47
  • Alex, just a quick one: This was straightforward as we compared all possible pairs of y[mandis][days] and checked whether they are in the same town. But what if I need to put an upper cap on the sum of all q[mandi][days] (q is the quantity of rice) within the same town on any given day? How should I model that constraint in CPLEX? Any help would be great. – Aman Kabra Aug 07 '20 at 04:48