Solver is usually used to find the "best" solution. We aim to maximize value in a knapsack problem, or maybe minimize the scheduling time required for a set of jobs to be completed on some machines, and so on.
But what if we would like to know the second, or third best choice? Maybe we can gain some insights into our problem exploring suboptimal solutions. There are some caveats, but with a bit of VBA this is a feasible problem (pun intended).
Let's start with a simple setup: we manage a business and want to choose from a list of people those that would maximize customers satisfaction. In this respect, each person has been rated from 0 to 20, and expects a pay that is known. Our maximum affordable payment is the only constraint on our choices. Just to make things a bit more interesting, we assume that there are 6 different roles, each one with a given number of persons to be hired.
Worksheet setup |
The core of the VBA code is as follows.
For i = 1 To 5
SolverReset
SolverOk SetCell:=Max_satisfaction.Address, MaxMinVal:=1, ByChange:=bin_vars.Address, Engine:=2
SolverAdd CellRef:=Total_payment.Address, Relation:=1, FormulaText:=Affordable.Address
SolverAdd CellRef:=constr_kind.Address, Relation:=2, FormulaText:=req_roles.Address
SolverAdd CellRef:=bin_vars.Address, Relation:=5
If i > 1 Then
SolverAdd CellRef:=Max_satisfaction.Address, Relation:=1, FormulaText:=curr_max & delta
End If
SolverOptions IntTolerance:=0, Scaling:=True
SolverSolve UserFinish:=True
curr_max = Range("Max_satisfaction").Value
delta = -curr_max * (10 ^ -6)
Next i
No comments:
Post a Comment