Originally posted by: Rodders
I have a set of stores, each of which belongs to a region.
BelongsTo[STOREs, REGIONs] looks like this:
[ [ 0 1 0 0 ] // store A
[ 0 0 1 0 ] // store B
[ 0 0 1 0 ] // store C
[ 0 0 0 1 ] // store D
[ 1 0 0 0 ] // store E
[ 1 0 0 0 ] // store F
[ 0 0 1 0 ] // store G
[ 0 0 1 0 ] // store H
[ 0 1 0 0 ] // store I
[ 1 0 0 0 ] // store J
[ 1 0 0 0 ] // store K
]
In this particular example there are 11 stores and 4 regions. Each store belongs to one and only one region.
Whenever a shipment is scheduled for a store, a fixed cost is assessed, associated with the region to which the store belongs.
If more than one store in the same region is serviced on a given day, that region's fixed cost is assessed only once.
I was able to successfully set the boolean decision variable WasVisited[REGIONs, DAYs] with the following constraint:
CheckRegionsVisited =
forall (r in REGIONs, d in DAYs, s in STOREs)
BelongsTo[s,r] * Truck[s,d] <= WasVisited [r,d];
So far, so good.
My only problem is due to my data file being dynamically prepared by an external application. The set of stores that will be present in the data file is unknown, on any given day.
The BelongsTo matrix mentioned in the beginning of this post contains all stores, but every time the model is executed I need to instantiate a version of that master matrix that represents only the stores that are present in the data file, in the order that they appear in the data file.
My data file contains the following data element:
STOREs = {
D F K
};
Each time the model is called, this data element will look different.
How do I dynamically (inside the "execute" preprocessing code) create a BelongsTo matrix that will correspond to the STOREs data element passed to the model?
If my STOREs data element looked like the one above, my BelongsTo matrix would need to look like this:
[ [ 0 0 0 1 ] // store D
[ 1 0 0 0 ] // store F
[ 1 0 0 0 ] // store K
]
This is what I've tried, so far:
-
Represent the master matrix as:
int BelongsTo[STOREs,REGIONs];
tuple MyMatrix {
int store;
int belongs[REGIONs];
};
{MyMatrix} hardcoded_matrix = { < A , [0, 1, 0, 0] >, < B , [0, 0, 1, 0] >, < C , [0, 0, 1, 0] > };
-
Attempt different versions of:
BelongsTo = [ h.belongs | h.store in STOREs, h in hardcoded_matrix ];
for (var x in STOREs)
BelongsTo = [ x : h.belongs | x = h.store , h in hardcoded_matrix ];
I believe I'm missing something in the syntax.
Does anyone know how I can dynamically create BelongsTo[STOREs, REGIONs], based on the value of STOREs read from the data file?
Or does anyone know of a better way to accomplish this?
Changing the data file is not possible at the moment.
Thank you very much for helping me crack this nut.
Marcelo
Solutions Architect
#DecisionOptimization#OPLusingCPLEXOptimizer