optimproblem object: Change variable bounds
2 ビュー (過去 30 日間)
古いコメントを表示
"OptimizationProblem property 'Variables' is read-only". That is the message I get after trying to change something like:
prob.Variables.x.LowerBound = lb
where prob is an optimproblem object.
How can I get around this? Another issue I found was that I could not add variables to the problem, for the same reason. I got around this by adding dummy constraints with all zero coefficients. Overall I like this new tool, it is very convenient, but there should be a way to manipulate variables easily. I am using 2017b.
5 件のコメント
Matt J
2018 年 1 月 23 日
If you can get it to work for you with other solvers, great, but it is outside of the current design scope to do so.
That seems to throw into question the purpose of offering a prob2struct() method in the first place.
On the other hand, I don't think it would be difficult for the user to reconstruct the connection between the problem-based names and the solver form, assuming TMW guarantees that the ordering of the variables/constraints in both forms will always be the same. I think this is undocumented, currently.
採用された回答
Matt J
2018 年 1 月 23 日
編集済み: Matt J
2018 年 1 月 23 日
How can I get around this?
It is odd to me as well that the prob.Variables property is read-only. However, I notice things are pretty easy if you haven't discarded the OptimizationVariable objects used to build prob. The optimvars are handles, so you can just change those directly and the changes will be reflected in the prob object as well. For example,
>> x=optimvar('x',1,2); prob.Objective=sum(x);
>> prob.Variables.x.LowerBound
ans =
-Inf -Inf
>> x.LowerBound=[2,3]; prob.Variables.x.LowerBound
ans =
2 3
If you have discarded the original OptimizationVariable objects, then you can recover them from the prob object and do likewise,
>> x=prob.Variables.x; x.LowerBound=[-7,-9]; prob.Variables.x.LowerBound
ans =
-7 -9
There are ways to wrap these operations in functions so that you can do them in a single command, of course.
Another issue I found was that I could not add variables to the problem, for the same reason.
Didn't understand this part. You mean you want to add variables to the problem that don't explicitly appear in either the objective or constraints? If so, why?
2 件のコメント
Matt J
2018 年 1 月 23 日
編集済み: Matt J
2018 年 1 月 23 日
OK, but then it seems to me that all you should have to do is modify prob.Objective or prob.Constraints. The new variables participating in them will automatically be added to the list, for example,
>> prob.Variables
ans =
struct with fields:
x: [1×2 optim.problemdef.OptimizationVariable]
>> y=optimvar('y'); prob.Objective=sum(prob.Variables.x)+y; prob.Variables
ans =
struct with fields:
x: [1×2 optim.problemdef.OptimizationVariable]
y: [1×1 optim.problemdef.OptimizationVariable]
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Systems of Nonlinear Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!