How to create a constraint function for optimisation
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Alan Weiss
le 23 Fév 2017
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 commentaires
Alan Weiss
le 24 Fév 2017
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
Voir également
Catégories
En savoir plus sur Genetic Algorithm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!