如何获得序列中的相邻间隔 [英] How can I get adjacent intervals in a sequence
本文介绍了如何获得序列中的相邻间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了一个间隔dvar来表示两个城市之间的路段,并定义了间隔上的dvar序列.现在,我要惩罚以下条件:如果某个区间的目的地城市不是下一个区间的出发城市,那么我在变量中计数1,例如,将其命名为countVar.我将在目标中最小化countVar.我该怎么办?
I define a dvar of interval to represent a leg between two cities, and a dvar sequence on the interval. rightnow, i want to punish the following condition: if the destination city of a interval is not the departure city of it's next interval, then I count 1 in a variable, for example, named it as countVar. and I will minimize the countVar in the objective. how can i do this?
推荐答案
///这是CPLEX程序
//Here is the CPLEX program
using CP;
tuple flightLeg{
key int LegID;
int departurePoint;
int destinationPoint;
int aircraftID;
}
{flightLeg} Legs=...;
tuple aircraft{
key int aircraftID;
int aircraftType;
}
{aircraft} aircraftSet=...;
tuple stop{
int LegID1;
int LegID2;
int stopTime;
}
{stop} stopTimes=...;
dvar interval invFlighttasks[i in Legs][j in aircraftSet] optional
size 10;
dvar sequence seqAircrafts[i in aircraftSet] in
all(j in Legs) invFlighttasks[j][i] types
all(j in Legs) j.LegID;
//minize the number of disconnect (means the destinationPoint of a interval
//is not the departurePoint of it's next interval)
subject to {
forall (i in aircraftSet)
noOverlap(seqAircrafts[i],stopTimes);
}
这篇关于如何获得序列中的相邻间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文