How can i sanction changes in linear optimization?

조회 수: 6 (최근 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 CenterFile Exchange에서 Get 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