Setting optimal value to lie in any of the given specified value

Viewed 302

I'm using open solver to solve an optimization problem. The problem is as follows:

Suppose I'm optimizing input with given total cost constraint and input availability. We have input cost and want to minimize the cost. The another constraint is the optimized input falls in any of the set value, say input11, input12, input13 and input14. This discrete input range varies across inputs.

So we have 3 constraints:

  1. budget,
  2. input capacity for each inputs and
  3. inputs should fall within any of the falling four options.

The portion of the code I created:

Sub TestOpensolver()

Dim TestSheet As Worksheet
Set TestSheet = Worksheets("Optimized_Results")

    OpenSolver.ResetModel Sheet:=TestSheet

    'Objective Definition
    OpenSolver.SetObjectiveFunctionCell TestSheet.Range("AC3"), Sheet:=TestSheet
    OpenSolver.SetObjectiveSense MinimiseObjective, Sheet:=TestSheet

    'Variables Definition
    OpenSolver.SetDecisionVariables TestSheet.Range("AK3:AK8"), Sheet:=TestSheet
    OpenSolver.SetDecisionVariables TestSheet.Range("AQ3:AR8"), Sheet:=TestSheet

    ' Constraints       

    OpenSolver.AddConstraint TestSheet.Range("AK3:AK8"), RelationLE, TestSheet.Range("W3:W8"), Sheet:=TestSheet
    OpenSolver.AddConstraint TestSheet.Range("AK3:AK8"), RelationGE, TestSheet.Range("X3:X8"), Sheet:=TestSheet


    OpenSolver.AddConstraint TestSheet.Range("AS3:AS8"), RelationLE, TestSheet.Range("AT3:AT8"), Sheet:=TestSheet


    OpenSolver.RunOpenSolver , False



End Sub

Can anyone please help me to solve the problem?

Thank you!

1 Answers
Related