"Conversion to optim.problemdef.OptimizationExpression from sym is not possible." I am getting this error and I am not able to understand how to resolve this error.
10 ビュー (過去 30 日間)
古いコメントを表示
Hi Everyone!
I am solving a optimization problem I faced a problem in that which shows errors like this. I have tried several times but could'nt help.
Below is the data file, below that will be the optimization problem code.
global SL V p r k m n C Z s
SL = [0.75 0.75 0.75 0.75];
V = 94100;
p = [0.07,0.18,0.2,0.3];
r = [55 55 55 55;
47 47 47 47;
45 45 45 45;
49 49 49 49];
k = [33 33 33 33;
28 28 28 28;
29 29 29 29;
30 30 30 30];
m = 4;
n= 4;
C = [78,69,70,73;
64,68,56,59;
34,39,42,41;
52,47,48,45];
Z =[250 250 250 250;
320 320 320 320;
440 440 440 440;
350 350 350 350];
s = [110,95,99,100];
% bguess = randi(4,4);
% bguess = (bguess<2);
% Q0 = [zeros(4,4) bguess];
% % call the solver
% xopt = fmincon(@EP, Q0,[],[],[],[],[],[],@Constraints,[]);
This the error it is showing when I am running the below code.
global r k m n C Z s
% Generating Variables
Q = optimvar('Q',m,n,'LowerBound',0,'UpperBound',Z);
b = optimvar('b',m,n,'Type','integer','LowerBound',0,'UpperBound',1);
x = sym('x',[4,1]);
rng
y = rand(4);
x = sym('x',[4,1]);
% syms x
% Objective Function:-
% optimization problem
demandprob = optimproblem;
% Revenue
revenue = sum(s*b*x,1);
% Cost
cost = sum(sum(C*b*y*Q,1),2);
%Salvage
salvage = sum(b*r*(sum(sum(y*Q - x,1),2)),1);
% Revenue when demand is more
revenue2 = sum(s*b*y*Q,2);
% Salvage when demand is more
salvage2 = sum(b*k*(x - sum(sum(y*Q,1),2)),1);
% The objective function to maximize the below Expected Profit
demandprob.Objective = int(((revenue - cost + salvage).*normpdf(x, 400, 100)),0,q); + int(((revenue2 - cost - salvage2).*normpdf(x, 400, 100)),q,Inf);
% Include the constraints in the problem.
demandprob.Constraints.budget = budget;
demandprob.Constraints.normal = normal;
demandprob.Constraints.con4 = con4;
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
% Call the solver to find the solution.
[sol,fval,exitflag,output] = solve(demandprob,'options',opts);
Anybody Please help I have tried several thins, atleast if any body can just give me hint so I could get a direction, It will be highly appreciable.
I am also this error too, which says At least one argument must be numeric.
I am also not able to understand this how to resolve. Please help anyone.
0 件のコメント
採用された回答
Alan Weiss
2020 年 7 月 23 日
You are mixing several data types in your problem. You cannot use optimization variables, symbolic variables, and numeric variables indiscriminantly comingled.
It appears that you want to take an integral involving symbolic variables, and that the range of the integral is infinite. You cannot perform this integration symbolically. Instead, convert your symbolic expressions to numeric using matlabFunction, perhaps along the lines of this example. Alternatively, write your function entirely using standard MATLAB numeric functions, and convert your expressions to optimization expressions using fcn2optimexpr. And you might need to cut down on the range of integration to make it finite, but maybe not.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!