英文:
CPLEX Constraint with sum operator
问题
我有一个优化问题,需要最小化电充电站的位置。因此,我需要一个约束条件,用于计算某一时间戳下一辆车的电池电量状态。我在建模这个约束条件时遇到了困难。
我有一个想法,大致如下:
对于所有的车辆和时间
stateofcharge[vehicle][time] = stateofcharge_start + ((累加到时间)gainedpower[vehicle][time] - (累加到时间)used power[vehicle][time])
我不知道如何将其转化为代码,我尝试过但一直出现错误。
英文:
Context: I have an optimisation problem, which minimises locations of electric charge stations. Therefore I need a constraint, which calculates the state of charge of one vehicle at a time stamp. I struggle with modelling that constraint.
I have something in mind which looks like this:
for all vehicles and times
stateofcharge[vehicle][time] = stateofcharge_start + ((sum up to time)gainedpower[vehicle][time] - (sum up to time)used power[vehicle][time])
I don't know how to put that into code, I tried but it keeps me giving errors.
答案1
得分: 0
你可以从以下代码开始:
int nbVeh=6;
int horizon=10;
range vehicle=1..nbVeh;
range time=1..horizon;
range time0=0..horizon;
float stateofcharge_start[vehicle]=[1,2,3,4,5,6];
dvar float+ stateoecharge[vehicle][time0];
dvar float+ gainedpower[vehicle][time];
dvar float+ usedpower[vehicle][time];
subject to
{
forall(v in vehicle)
stateoecharge[v][0]==stateofcharge_start[v];
forall(v in vehicle,t in time)
stateoecharge[v][t]==stateoecharge[v][t-1]+gainedpower[v][t]-usedpower[v][t];
}
英文:
You could start with
int nbVeh=6;
int horizon=10;
range vehicle=1..nbVeh;
range time=1..horizon;
range time0=0..horizon;
float stateofcharge_start[vehicle]=[1,2,3,4,5,6];
dvar float+ stateoecharge[vehicle][time0];
dvar float+ gainedpower[vehicle][time];
dvar float+ usedpower[vehicle][time];
subject to
{
forall(v in vehicle)
stateoecharge[v][0]==stateofcharge_start[v];
forall(v in vehicle,t in time)
stateoecharge[v][t]==stateoecharge[v][t-1]+gainedpower[v][t]-usedpower[v][t];
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论