How to create a constraint function for optimisation
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to run an optimisation where I have cars arriving and departing at various times and are assigned to a specific space, but I am struggling with the constraints. I am wanting constraints that only 1 cars is assigned to a space at the one time and that a car is assigned to one space and one space only. Any help?
0 件のコメント
回答 (1 件)
Alan Weiss
2017 年 2 月 23 日
It depends on whether your variables are integer-valued or not. If they are integers and you have a mixed-integer linear programming problem, then see this example, which has constraints that each office can have no more than one person, and each person must be in an office.
If you have non-integer variables, then I am not sure how you can make constraints for this problem. And if you have a nonlinear problem, then you could try to use the mixed-integer genetic algorithm solver, though it is not generally effective on problems with more than a few dozen variables.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
2 件のコメント
Alan Weiss
2017 年 2 月 24 日
Basically, make a 2-D array of binary variables, x(i,j), where the i variable indexes the cars, and the j variable indexes the parking spaces. The variable is 1 when car i is in space j, and is zero otherwise. Then the constraint that each car is in some space is
sum(x,2) = ones(numi,1);
and the constraint that each parking spot has no more than one car in it is
sum(x,1) <= ones(1,numj);
Here I mean the standard MATLAB notation for summation, where sum(x,2) means the summation on j of x(i,j). And numi and numj is the number of i and j variables, respectively.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!