使用约束规划 (CPLEX) 时的未绑定表达式

问题描述 投票:0回答:1

我正在根据 Kyle.E.C.Booth 的论文“A Constraint Planning Approach to Electric Vehicle Routing with Time Windows”使用 CP 编码模型

using CP;

int NoDepot = ...;
int NoCharge = ...;
int NoCustomer = ...;
int NoVehicle = ...;

range depot = 1 .. NoDepot;
range dummydepot = NoDepot+1 .. NoDepot*2;
range charge = NoDepot*2+1 .. NoDepot*2+NoCharge;
range customer = NoDepot*2+NoCharge+1 .. NoDepot*2+NoCharge+NoCustomer;
range allnode = 1..NoDepot*2+NoCharge+NoCustomer;
range vehicle = 1..NoVehicle;

int start[allnode] = ...;
int end[allnode] = ...;

int demand[customer] = ...;
int servicetime[customer] = ...;
int batterycapa[vehicle] = ...;
int loadcapa[vehicle] = ...;

int consumerate = 1;
int rechargerate = 1;

int alpha = 1;
int beta = 1;

int distancematrix[0..NoDepot*2+NoCharge+NoCustomer][0..NoDepot*2+NoCharge+NoCustomer] = ...; 
int timematrix[0..NoDepot*2+NoCharge+NoCustomer][0..NoDepot*2+NoCharge+NoCustomer] = ...;

tuple triplet { int id1; int id2; int value; };
{triplet} Mdist = {<id1,id2,distancematrix[id1][id2]> | id1,id2 in allnode};
{triplet} Mtime = {<id1,id2,timematrix[id1][id2]> | id1,id2 in allnode};

dvar interval visit[c in customer] in start[c]..end[c] size servicetime[c];
dvar interval vehvisit_dist[a in allnode][v in vehicle] optional size 0;
dvar interval vehvisit_time[a in allnode][v in vehicle] optional;

dvar sequence route_dist[v in vehicle] in all (a in allnode)vehvisit_dist[a][v] types all(a in allnode) a;
dvar sequence route_time[v in vehicle] in all (a in allnode)vehvisit_time[a][v] types all(a in allnode) a;

dvar interval vehicle_dist[v in vehicle] optional;


cumulFunction carry_load[v in vehicle] = stepAtStart(vehvisit_time[1][v],loadcapa[v]) 
                - sum(c in customer)stepAtStart(vehvisit_time[c][v],demand[c]);

cumulFunction battery_load[v in vehicle] = stepAtStart(vehvisit_time[1][v],batterycapa[v]) 
    - sum(b in allnode)stepAtEnd(vehvisit_time[b][v],distancematrix[typeOfPrev(route_time[v], vehvisit_time[b][v],0,0)][b]) + sum(f in charge)stepAtStart(vehvisit_time[f][v],0,batterycapa[v]);


subject to
{
    
    ct1:
    forall(c in customer)
        alternative(visit[c],all(v in vehicle)vehvisit_time[c][v]);
    
    ct2:
    forall(v in vehicle)
        noOverlap(route_dist[v],Mdist,true);
    
    ct3:
    forall(v in vehicle)
        noOverlap(route_time[v],Mtime,true);
    
    ct4:
    forall(v in vehicle)
        sameSequence(route_dist[v], route_time[v]);
    
    ct5:
    forall(v in vehicle)
        presenceOf(vehvisit_time[1][v]);
        
    ct6:
    forall(v in vehicle)
        presenceOf(vehvisit_time[2][v]);

    ct7:
    forall(v in vehicle)
    {
        first(route_time[v],vehvisit_time[1][v]);
        last(route_time[v],vehvisit_time[2][v]);        
    }   
    
    ct8:
    forall(v in vehicle)
        span(vehicle_dist[v], all(a in allnode)vehvisit_time[a][v]);

    ct9:
    forall(v in vehicle)
        alwaysIn(carry_load[v],start[1], end[1], 0, loadcapa[v]);
    
    ct10:
    forall(v in vehicle)
        alwaysIn(battery_load[v],start[1], end[1], 0, batterycapa[v]);
    
    ct11:
    forall(v in vehicle, f in charge)
        alwaysIn(battery_load[v],vehvisit_time[f][v],batterycapa[v],batterycapa[v]);
}


///////////// .dat file
SheetConnection file("final.xlsx");

NoDepot from SheetRead(file, "NoDepot");
NoCharge from SheetRead(file, "NoCharge");
NoCustomer from SheetRead(file, "NoCustomer");
NoVehicle from SheetRead(file, "NoVehicle");
start from SheetRead(file, "start");
end from SheetRead(file, "end");
demand from SheetRead(file, "demand");
servicetime from SheetRead(file, "servicetime");
batterycapa from SheetRead(file, "batterycapa");
loadcapa from SheetRead(file, "loadcapa");
distancematrix from SheetRead(file, "dist");
timematrix from SheetRead(file, "time");



以 Excel 格式链接数据:: https://docs.google.com/spreadsheets/d/1ou-AO-CmWz80dynkEivm432rjBPfCSWY/edit?usp=sharing&ouid=110647671445738653790&rtpof=true&sd=true

我有一个错误: 未绑定表达式:side stepAtStart 函数中的 distancematrix[typeOfPrev(route_time[v1],vehvisit_time[b][v1],0,0)][b]

我已经尝试了很多次了,但还是不行,请帮助我,谢谢 更新1: 我已经阅读了ibm关于函数stepAtStart([interval variable], int hmin, int hmax)的文档

  • hmax 和 hmin 是预先定义的,就像距离矩阵一样。但我仍然收到错误

更新2: 我发现函数“typeOfPrev”不能位于函数“stepAtEnd”内部

cplex constraint-programming
1个回答
0
投票

StepAtEnd 中的高度可以是一个整数或两个整数边界,但不能是表达式。

© www.soinside.com 2019 - 2024. All rights reserved.