问题描述
我对CPLEX还是陌生的,正在尝试了解一个朋友的示例,以便我自己创建模型,但是我对如何创建一个决策变量感到困惑。这个符号令我感到不熟悉,也让他们感到不熟悉,因为他们使用的是一组元组及其定义中的范围。
I am very new to CPLEX and am trying to understand a friends example so i may produce a model myself, however I am confused as to how one of the decision variables has been created. The notation is unfamiliar to me and also the fact that they are using a set of tuples as well as ranges in it's definition. Any help explaining what is going on and what the line of code does would be greatly appreciated.
tuple bus{int busnumber; float capacity; string start_location; string stop_location; int maxleg;};
{bus} busfleet=...;
int maxroute=...;
range route = 1..maxroute;
range route0 = 1..maxroute-1;
tuple job {string start_location; string stop_location; int runafter; int runbefore; int runstop; float demand;};
{job} jobs=...;
{job} initialjobs=...;
{job} jobs1=...;
{job} alljobs = initialjobs union jobs union jobs1;
//variable
dvar boolean scheduleofbus[busfleet, route, alljobs, alljobs];
我的困惑涉及到最后一行,其中定义了 scheduleofbus。数组的此初始化做什么?如果可能的话,您还可以帮助定义尺寸,选择元素的方式等等。我们将不胜感激。提前谢谢了。 =)
My confusion concerns the final line, where "scheduleofbus" is defined. What does this initialization of the array do? If possible could you also help define it's dimensions, what selecting an element of it would do etc. Any help would be greatly appreciated. Many thanks in advance. =)
推荐答案
行
dvar boolean scheduleofbus[busfleet, route, alljobs, alljobs];
可以等效地写为
dvar boolean scheduleofbus[busfleet][route][alljobs][alljobs];
这可能会更明显。它定义了一个4维布尔决策变量。为此变量设置的索引是 busfleet
, route
,中元素的笛卡尔积alljobs
和 alljobs
(是的,alljobs出现两次)。
which may be a bit more obvious. It defines a 4-dimensional boolean decision variable. The index set for this variable is the cartesian product of the elements in busfleet
, route
, alljobs
and alljobs
(yes, alljobs appears twice).
对于公交车,路线和工作对的每种组合,您都有一个变量。
In other words, you have a variable for each combination of bus, route and pair of jobs.
这篇关于这个数组初始化是什么意思?聚氯乙烯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!