Skip to content

Commit b7b3bfb

Browse files
committed
version update
Added no registration test renamed slvDif member of SlvRelation enum to slvAllDif renamed SlvReturnMsgCode enum to SlvMsgCode renamed slvSolutionFound member of SlvMsgCode enum to slvFoundSolution Moved/Renamed SolverCodeToString method of SolvProblem class to MsgCodeToString method of SolvSolver class
1 parent a4ee629 commit b7b3bfb

24 files changed

+162
-94
lines changed

dev/ActiveX_DLL/no_registration/modGlobals.bas

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Public Enum SlvRelation
4747
slvGreaterThanEqual = 3
4848
slvInt = 4
4949
slvBin = 5
50-
slvDif = 6
50+
slvAllDif = 6
5151
[_First] = 1
5252
[_Last] = 6
5353
End Enum
@@ -70,8 +70,16 @@ Public Enum SlvCallbackReason
7070
[_Last] = 5
7171
End Enum
7272

73-
Public Enum SlvReturnMsgCode
74-
slvSolutionFound = 0
73+
Private Enum SolverMode
74+
SolveMode = 0
75+
CloseMode = 1
76+
CancelRestoreMode = 2
77+
[_First] = 0
78+
[_Last] = 2
79+
End Enum
80+
81+
Public Enum SlvMsgCode
82+
slvFoundSolution = 0
7583
slvConvergedOnSolution = 1
7684
slvCannotImproveSolution = 2
7785
slvMaxIterReached = 3
@@ -95,3 +103,4 @@ Public Enum SlvReturnMsgCode
95103
[_First] = 0
96104
[_Last] = 20
97105
End Enum
106+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Attribute VB_Name = "test_Portfolio_of_Securities"
2+
'@folder("SolverWrapper.Examples")
3+
4+
Option Explicit
5+
6+
'This example automates solving the problem in SOLVSAMP.XLS on the "Portfolio of Securities" worksheet.
7+
'
8+
'SOLVSAMP.XLS is distributed with MS Office Excel and can be found in:
9+
'
10+
'Application.LibraryPath & "\..\SAMPLES\SOLVSAMP.XLS"
11+
'
12+
'which on many systems can be found here:
13+
'C:\Program Files\Microsoft Office\root\Office16\SAMPLES\SOLVSAMP.XLS
14+
'
15+
'Import this module into the sample workbook, set a reference to the SolverWrapper code library
16+
'and then save SOLVSAMP.XLS to SOLVSAMP.XLSM.
17+
18+
'This is a non-linear problem - use slvGRG_Nonlinear
19+
Sub Solve_Portfolio_of_Securities()
20+
Dim Problem As Object
21+
Dim ws As Worksheet
22+
23+
Set Problem = New_SolvProblem
24+
25+
Set ws = ThisWorkbook.Worksheets("Portfolio of Securities")
26+
27+
'initialize the problem by passing a reference to the worksheet of interest
28+
Problem.Initialize ws
29+
30+
'define the objective cell to be optimized
31+
Problem.Objective.Define "E18", slvMaximize
32+
33+
'define and initialize the decision cell(s)
34+
Problem.DecisionVars.Add "E10:E14"
35+
Problem.DecisionVars.Initialize 0.2, 0.2, 0.2, 0.2, 0.2
36+
37+
'add some constraints
38+
Problem.Constraints.AddBounded "E10:E14", 0#, 1#
39+
Problem.Constraints.Add "E16", slvEqual, 1#
40+
Problem.Constraints.Add "G18", slvLessThanEqual, 0.071
41+
42+
'set the solver engine to use
43+
Problem.Solver.Method = slvGRG_Nonlinear
44+
45+
'set some solver options
46+
Problem.Solver.Options.AssumeNonNeg = True
47+
Problem.Solver.Options.RandomSeed = 7
48+
49+
Problem.Solver.SaveAllTrialSolutions = True
50+
51+
'solve the optimization problem
52+
Problem.SolveIt
53+
54+
'save all trial solutions that passed the constraints to the worksheet
55+
If Problem.Solver.SaveAllTrialSolutions Then
56+
ws.Range("o2:az10000").ClearContents
57+
Problem.SaveSolutionsToRange ws.Range("o2"), keepOnlyValid:=True
58+
End If
59+
End Sub

dist/SolverWrapperDLLSetup.exe

203 Bytes
Binary file not shown.
-310 Bytes
Binary file not shown.

src/twinBASIC/source/ClassFactory.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Attribute VB_Description = "This class is used for object instantiation when ref
33
'%ModuleDescription "This class is used for object instantiation when referencing SolverWrapper externally from another VBA project"
44
'@folder("SolverWrapper.Source")
55
' ==========================================================================
6-
' SolverWrapper v0.4
6+
' SolverWrapper v0.6
77
'
88
' A wrapper for automating MS Excel's Solver Add-in
99
'

src/twinBASIC/source/SolvConstraints.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to set/manage Solver constraints."
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.4
15+
' SolverWrapper v0.6
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'
@@ -84,7 +84,7 @@ Attribute Add.VB_Description = "Adds a constraint to the current problem."
8484
ws.Names.Add Name:="solver_rhs" & CStr(solver_num), RefersTo:="=""integer""", Visible:=nameVisible
8585
Case SlvRelation.slvBin
8686
ws.Names.Add Name:="solver_rhs" & CStr(solver_num), RefersTo:="=""binary""", Visible:=nameVisible
87-
Case SlvRelation.slvDif
87+
Case SlvRelation.slvAllDif
8888
ws.Names.Add Name:="solver_rhs" & CStr(solver_num), RefersTo:="=""AllDifferent""", Visible:=nameVisible
8989
End Select
9090
Else 'Relation <=3
@@ -183,7 +183,7 @@ Attribute Relax.VB_Description = "Deletes a constraint from the current problem.
183183
ws.Names.Add Name:="solver_rhs" & CStr(solver_num), RefersTo:="=""integer""", Visible:=nameVisible
184184
Case SlvRelation.slvBin
185185
ws.Names.Add Name:="solver_rhs" & CStr(solver_num), RefersTo:="=""binary""", Visible:=nameVisible
186-
Case SlvRelation.slvDif
186+
Case SlvRelation.slvAllDif
187187
ws.Names.Add Name:="solver_rhs" & CStr(solver_num), RefersTo:="=""AllDifferent""", Visible:=nameVisible
188188
End Select
189189
Else 'Relation <=3
@@ -296,7 +296,7 @@ Private Sub ProcessConstraintParams(ByRef cellRef As Variant, ByVal relation As
296296
'check that lhs refer(s) to the decision variables
297297
If relation > 3 Then
298298
If Not NameExists("solver_adj", ws) Then
299-
Err.Raise vbObjectError + 4001, , "Cannot set constraint relations slvInt, slvBin, or slvDif, until after the decision variables are defined."
299+
Err.Raise vbObjectError + 4001, , "Cannot set constraint relations slvInt, slvBin, or slvAllDif, until after the decision variables are defined."
300300
End If
301301
If Not IsRangeInRange(ws.Range(cellRef), ws.Range(ws.Names("solver_adj").Name)) Then
302302
'they are not the same

src/twinBASIC/source/SolvDLL.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Attribute VB_Description = "This private class is used to communicate directly w
1111
'%ModuleDescription "This private class is used to communicate directly with DLL and is not exposed to User."
1212
'@folder("SolverWrapper.Source")
1313
' ==========================================================================
14-
' SolverWrapper v0.4
14+
' SolverWrapper v0.6
1515
'
1616
' A wrapper for automating MS Excel's Solver Add-in
1717
'
@@ -182,7 +182,7 @@ Public Function RunSolver() As Long
182182
RunSolver = returnMsgCode
183183

184184
'post return message to status bar
185-
Application.StatusBar = ReturnSolverMsg(returnMsgCode)
185+
Application.StatusBar = "Excel Solver - " & ReturnSolverMsg(returnMsgCode)
186186

187187
'finish up on events
188188
If enableInternalEvents Then

src/twinBASIC/source/SolvDecisionVars.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to define the Decision variable, i.e. the ce
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.4
15+
' SolverWrapper v0.6
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'

src/twinBASIC/source/SolvObjective.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to define the Solver Objective function."
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.4
15+
' SolverWrapper v0.6
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'

src/twinBASIC/source/SolvOptions.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Attribute VB_Description = "A class to set Solver Options."
1212
'@Exposed
1313
'@folder("SolverWrapper.Source")
1414
' ==========================================================================
15-
' SolverWrapper v0.4
15+
' SolverWrapper v0.6
1616
'
1717
' A wrapper for automating MS Excel's Solver Add-in
1818
'

0 commit comments

Comments
 (0)