-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boundaries for the variables #106
Comments
That's what "constraints": {
"oatmeal": {"max": 4},
},
"variables": {
"oatmeal": {"oatmeal": 1 },
}, Would ensure that the maximum value for the variable |
"oatmeal": {"oatmeal": 1 }, |
This means for each oatmeal in the solution you want the oatmeal variable to increase by one. |
Maybe I'm missing something here, but I don't seem to be able to set a negative lower bound on a variable. Is there always an implicit positivity constraint for every variable? |
@waeltut try this: let model = {
"name": "food",
"optimize": "cost",
"opType": "min",
"constraints": {
"oatmeal": {
"max": 4
},
"chicken": {
"max": 3
},
"egg": {
"max": 2
},
"milk": {
"max": 8
},
"muffin": {
"max": 2
},
"soup": {
"max": 2
},
"kcal": {
"min": 2000
},
"prot": {
"min": 55
},
"ca": {
"min": 800
}
},
"variables": {
"oatmeal": {
"kcal": 110,
"prot": 4,
"ca": 2,
"cost": 0.1,
"oatmeal": 1
},
"chicken": {
"kcal": 205,
"prot": 32,
"ca": 12,
"cost": 0.8,
"chicken": 1
},
"egg": {
"kcal": 160,
"prot": 13,
"ca": 54,
"cost": 0.4,
"egg": 1
},
"milk": {
"kcal": 160,
"prot": 8,
"ca": 285,
"cost": 0.3,
"milk": 1
},
"muffin": {
"kcal": 420,
"prot": 4,
"ca": 22,
"cost": 0.7,
"muffin": 1
},
"soup": {
"kcal": 260,
"prot": 14,
"ca": 80,
"cost": 0.6,
"soup": 1
}
}
}
let results = solver.Solve(model);
// See what we have so far...
console.log(results);
// Roll it all up for proof:
let output = {};
Object.keys(results).forEach(function(rAttr){
if(model.variables[rAttr]){
let tmp = model.variables[rAttr];
for(attr in tmp){
output[attr] = output[attr] || 0;
output[attr] += tmp[attr] * results[rAttr]
}
}
})
console.log(output); |
If I wanted to set the constraints this way, would it be correct? "constraints": { |
I could not find the way of adding upper and lower boundaries for variables. is it an attribute "max", "min" for each variable?
The text was updated successfully, but these errors were encountered: