Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OpenSolver API example
Sub Model_Creation()
Dim TestSheet As Worksheet
Set TestSheet = Sheets("test")
OpenSolver.ResetModel Sheet:=TestSheet
'Objective Definition
OpenSolver.SetObjectiveFunctionCell TestSheet.Cells(1, 1), Sheet:=TestSheet
OpenSolver.SetObjectiveSense MinimiseObjective, Sheet:=TestSheet
'Variables Definition
OpenSolver.SetDecisionVariables Union(TestSheet.Range(Cells(3, 1), Cells(3, 4)), TestSheet.Range(Cells(5, 1), Cells(5, 4))), Sheet:=TestSheet
'Constraints Definition
OpenSolver.AddConstraint TestSheet.Range(Cells(3, 1), Cells(3, 4)), RelationBIN, Sheet:=TestSheet
OpenSolver.AddConstraint TestSheet.Range(Cells(7, 1), Cells(7, 4)), RelationLE, TestSheet.Range(Cells(8, 1), Cells(8, 4)), Sheet:=TestSheet
OpenSolver.AddConstraint TestSheet.Range(Cells(10, 1), Cells(10, 4)), RelationGE, TestSheet.Range(Cells(11, 1), Cells(11, 4)), Sheet:=TestSheet
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.