CPLEX约束与求和运算符

huangapple go评论134阅读模式
英文:

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];
}

huangapple
  • 本文由 发表于 2023年3月7日 00:29:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定