ABS function not supported in problem type 'optim.pro​blemdef.Op​timization​Expression​'.

6 views (last 30 days)
% %% 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)

Answers (1)

Rajani Mishra
Rajani Mishra on 6 Jan 2020
The error encountered : 'optim.pro​blemdef.Op​timization​Expression​' 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.

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!