ABS function not supported in problem type 'optim.problemdef.OptimizationExpression'.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% %% initialise slots request, social valur, capacity %%
% %% decision variable type: alloted matrix,social value function, capacity required %%
clc
clear all
cap = 3
bigCAP = 5;
s_v = 2.5
basic_data = readmatrix('book1.xlsx')
a = max(basic_data(:,1));
slot = [1:a,100]
for i =1:length(basic_data)
request(i,basic_data(i,1)) = 1
s(i,:) = basic_data(i,3)
end
z = zeros(length(basic_data),1);
request(:,end+1)=z;
pair = [2,4,1];
size_p =size(pair);
size_r =size(request);
allot_prob = optimproblem;
decision_variable = optimvar('decision_variable',size_r(1),size_r(2),'Type','integer','LowerBound',0,'UpperBound',1)
e = optimvar('e',1,size_r(2),'Type','integer','LowerBound',0,'UpperBound',2)
y = optimvar('y',1,size_r(2),'Type','continuous','LowerBound',0)
% %% Calculate difference between requested and alloted slot%%
[I,J] = find(request > 0)
for i=1:size_r(1)
n(i) = (request(I(i),J(i)) - decision_variable(I(i),J(i)))
end
c = sum(n) %% x(i,a)* |t-t(m)| %%
%%----------------------------------------------------------------------------------%%
for i = 1:size_r(1)
value(i) = sum(abs(slot.*request(i,:) - slot.*decision_variable(i,:)))
value1 = sum(value)
end
%%----------------------------------------------------------------------------------%%
for i = 1:size_p(1) %% pairwise movement %%
pairwise (i) =sum(slot.*decision_variable(pair(i,2),:)) - sum(slot.*decision_variable(pair(i,1),:)) >= pair(i,3)
end
allot_prob.Constraints.pairwise = pairwise;
%%----------------------------------------------------------------------------------%%
for i=1:size_r(1) %% one slot per movement %%
move_const(i) =sum(decision_variable(i,:)) == 1;
end
allot_prob.Constraints.move_const = move_const;
%%----------------------------------------------------------------------------------%%
for i=1:size_r(2)-3; %% capacity constraint%%
cap_const(i)=sum(decision_variable(:,i))+ sum(decision_variable(:,i+1))+ sum(decision_variable(:,i+2))<= cap + e(i) + e(i+1) + e(i+2);
end
cap_const(size_r(2)-3) = sum(decision_variable(:,size_r(2)-3)) <= cap/3 + e(size_r(2)-3)
cap_const(size_r(2)-2) = sum(decision_variable(:,size_r(2)-2)) <= cap/3 + e(size_r(2)-2)
cap_const(size_r(2)-1) = sum(decision_variable(:,size_r(2)-1)) <= cap/3 + e(size_r(2)-1)
allot_prob.Constraints.cap_const = cap_const;
%%----------------------------------------------------------------------------------%%
for i=1:(size_r(2)-3); %% social value constraint%%
social_value(i)=sum(decision_variable(:,i).*s + decision_variable(:,i+1).*s + decision_variable(:,i+2).*s) + y(i) >= (cap + e(i))*s_v
end
allot_prob.Constraints.social_value = social_value;
%%----------------------------------------------------------------------------------%%
Y = sum(y)
E = sum(e)
cap_const(size_r(2))=sum(decision_variable(:,size_r(2)))<=bigCAP, %% rejected slot %%
allot_prob.Constraints.cap_const = cap_const
%%----------------------------------------------------------------------------------%%
allot_prob.Objective = -value1 + 1000*c + E + Y; %% objective function %%
showproblem(allot_prob)
[sol,fval] = solve(allot_prob);
%%----------------------------------------------------------------------------------%%
[J] = find(request)
[Y] = find(sol.decision_variable)
0 commentaires
Réponses (1)
Rajani Mishra
le 6 Jan 2020
The error encountered : 'optim.problemdef.OptimizationExpression' is because of the abs function used in the code at the line : 'value(i) = sum(abs(slot.*request(i,:) - slot.*decision_variable(i,:)))'
abs() function is not supported on optimization variables and expressions. The code runs successfully without the use of abs function.
For list of operations supported please refer : https://www.mathworks.com/help/optim/ug/supported-operations-on-optimization-variables-expressions.html
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!