How to create a constraint function for optimisation

조회 수: 2 (최근 30일)
callum connacher
callum connacher 2017년 2월 23일
댓글: Alan Weiss 2017년 2월 24일
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