Given a theatre of 200 seats, find the best-recommended configuration of seating for each group that can fit all 200 seats given that a row only consists of 8 seats.
var javascriptLpSolver = require("javascript-lp-solver")
var groups = [30, 43, 15, 20, 89, 3]
var sum = groups.reduce(function(a, b){
return a + b;
}, 0);
for(var i=0; i<groups.length; i++){
var solver = javascriptLpSolver,
results,
model = {
"optimize": "cost",
"opType": "min",
"constraints": {
"person": {"equal": groups[i]},
"cost": {"max": 3*groups[i]},
"total_seats": {"max": sum}
},
"variables": {
"one-seater": {
"person": 1,
"cost": 3
},
"two-seater": {
"person": 2,
"cost": 2
},
"three-seater": {
"person": 3,
"cost": 1
},
"four-seater": {
"person": 4,
"cost": 1
},
"five-seater": {
"person": 5,
"cost": 1
},
"six-seater": {
"person": 6,
"cost": 1
},
"seven-seater": {
"person": 7,
"cost": 3
},
"eight-seater": {
"person": 8,
"cost": 1
},
},
"ints": {"one-seater": 1, "two-seater": 1, "three-seater": 1, "four-seater": 1, "five-seater": 1, "six-seater": 1, "seven-seater": 1, "eight-seater": 1,}
};
results = solver.Solve(model);
console.log(results);
}
Currently, it calculates the recommended configuration correctly per group based on a weightage scheme from 1-Seater to 8-Seater (where undesirable configurations like 1/7-Seaters 'costs' more compared to others) but it doesn't take into consideration if the recommended configuration fits into the leftover seats.
Here are the results given by the Solver:

If I follow the recommended configurations fully, I would be left with 20 seats that are empty:

How can I tweak the constraint of the LP to check if a configuration is valid?