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?

回答(1 个)

Alan Weiss
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 个评论
callum connacher
callum connacher 2017-2-24
Yeah I had a look at the example earlier but didn't really understand what it was doing. It is an integer problem so relates to that example. Could you break it down a wee bit? Help would be greatly appreciated.
Alan Weiss
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 CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by