How can i sanction changes in linear optimization?

4 ビュー (過去 30 日間)
Niklas Karstadt
Niklas Karstadt 2021 年 5 月 4 日
回答済み: prabhat kumar sharma 2025 年 1 月 16 日
I am trying to optimize Electrical Vehicle charge using a limited number of chargers. (Right now only looking at one hour)
The following Code is working:
% Define max. charger currrent, car capacity and max. car current
charger = [11,22,50];
cars = [10,20,30,40];
maxCurrentCar = [11,22,11,22];
x = optimvar('x',length(cars),length(charger),'LowerBound',0);
chargerconstr = sum(x,1) <= charger;
carcapconstr = sum(x,2) <= cars';
cartimeconstr = sum(x,2) <= maxCurrentCar';
chargertimeconstr = sum(x,1) <= charger;
prob = optimproblem;
prob.Objective = -1*sum(sum(x));
prob.Constraints.laderconstr = chargerconstr;
prob.Constraints.autoladungconstr = carcapconstr;
prob.Constraints.autozeitconstr = cartimeconstr;
prob.Constraints.ladezeitconstr = chargertimeconstr;
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
[sol,fval,exitflag,output] = solve(prob,'options',opts);
As a result i get the matrix
0 0 10
0 20 0
11 0 0
0 2 20
Looking at row 4 i now would like to sanction the use of multiple chargers (if not really necessary). My idea would be to tell the car it need like 10 minutes to switch between chargers.
How would i do this?
I already tried implementing binary variables into the model, but without success.

回答 (1 件)

prabhat kumar sharma
prabhat kumar sharma 2025 年 1 月 16 日
Hello Niklas,
To limit cars to using one charger at a time, introduce binary variables to indicate charger usage. Here's a streamlined approach:
  1. Binary Variables: Create y(i,j) to show if car i uses charger j.
  2. Constraints:
  • Link x(i,j) (charging amount) to y(i,j) using a large constant (bigM): x(i,j) <= bigM * y(i,j).
  • Ensure each car uses at most one charger: sum(y, 2) <= 1.
3. Objective: Maximize charging without changes.
charger = [11, 22, 50];
cars = [10, 20, 30, 40];
maxCurrentCar = [11, 22, 11, 22];
x = optimvar('x', length(cars), length(charger), 'LowerBound', 0);
y = optimvar('y', length(cars), length(charger), 'Type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
bigM = max(charger);
prob = optimproblem;
prob.Objective = -sum(sum(x));
prob.Constraints.chargerconstr = sum(x, 1) <= charger;
prob.Constraints.carcapconstr = sum(x, 2) <= cars';
prob.Constraints.cartimeconstr = sum(x, 2) <= maxCurrentCar';
prob.Constraints.useChargerConstr = x <= bigM * y;
prob.Constraints.oneChargerPerCarConstr = sum(y, 2) <= 1;
opts = optimoptions('intlinprog', 'Display', 'off', 'PlotFcn', @optimplotmilp);
[sol, fval, exitflag, output] = solve(prob, 'options', opts);
disp(sol.x);
I hope it helps!

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by