Originally posted by: SystemAdmin
[jfk said:]
Hello there,
well, without learning the OPL syntax you will not get far. I modified the code so it runs and compute some solution, but I don't think the constraints make much sense (sorry I didn't catch the meaning or purpose of your constraint seeds).
But why do you start with trasnp4.prj which is a more advanced tuple-based modeling? Start with transp1.prj first. The doc describe the problem/modeling as well.
Looking at transp4.prj you might ask why do we need this complex structure of the data, why don't we have some simpler structure of demand-supply and everything (like in transp1.prj)? Well, the thing is that if you want to get your data from a DB then you may not have a choice on the data structure, you are obliged to get it as it is provided and you have to do the data massaging by yourself. Here the tuples gives you tremendous help and the transp4.prj example shows you how to do the data transformation which best fits to your opti model. Just compare the data structure in transp1.dat and transp4.dat and you will see that trasnp4.dat is more compact (well, in my view the modeling becomes elegant as well, but it is a personal opinion).
so the corrected code of yours
.mod
--------------start
int TotalNods = ...;
range NodsOrder = 0..TotalNods ;
int DistMatrix[NodsOrder][NodsOrder] = ...;
int CostMatrix[NodsOrder][NodsOrder] = ...;
int NodQuantity[NodsOrder] = ...;
dvar int Road[NodsOrder][NodsOrder] in 0..1;
dvar int Volumn[NodsOrder];
minimize
sum(i in NodsOrder, j in NodsOrder) CostMatrix[i][j]*Road[i][j];
subject to {
forall( i in NodsOrder)
sum(j in NodsOrder) Road[i][j] == 1 + Road[0][0] ;
/* (1)
forall( i in NodsOrder)
sum(i in NodsOrder) Road
* == 1 + Road[0][0]; //(2)
/
forall(i in NodsOrder, j in NodsOrder)
sum(i in NodsOrder, j in NodsOrder : i!=j) Road[i][j] == sum(i in NodsOrder) Road[i][j] + 1; //(3)
};
/Questions:
a. How to evaluate the 2-dimension array (e.g. DistMatrix[NodsOrder][NodsOrder]) - see in the code
b. I want the the value of decision variable Road[NodsOrder][NodsOrder] only can choose 0 or 1. - see in the code
c. in the constraints equation (3), I want to sum it all while ij. Could my program work? - see in the code
d. My LP problem is some Transport problem. There is an example transp4.prj. But some program I can not catch it at all.
e.g. {route} Routes = { < p,<o,d> > | <p,o,d,c> in TableRoutes };
{connection} Connections = { c | <p,c> in Routes }; - see ABOVE
*/
--------------end
.dat
--------------start
otalNods = 3;
DistMatrix = [[1,2,3],
[1,2,3],
[1,2,3]];
CostMatrix = [[111,222,3],
[1,222,333],
[111,2,333]];
NodQuantity = [11,22,33];
--------------end
BTW 2 questions:
1. which version of OPL are you using?
2. would you share with me the name of the University of yours?
cheers
#DecisionOptimization#OPLusingCPOptimizer