-
Notifications
You must be signed in to change notification settings - Fork 1
Object Model Overview
Below is an overview of the SolverWrapper Object Model. See the Wiki Home for usage topics.
This class is used for object instantiation when referencing SolverWrapper externally from another code project. It is not needed if referencing SolverWrapper from within the same project or when using the twinBASIC ActiveX DLL solution. Example usage:
Dim problem As SolverWrapper.SolvProblem
Set problem = SolverWrapper.New_SolvProblem
Class | Method/Property | Description |
---|---|---|
ClassFactory | New_SolvProblem | Instantiates a SolvProblem object |
A class to set/manage Solver constraints. Example usage:
Problem.Constraints.Add "B14:G14", slvGreaterThanEqual, 0
Class | Method/Property | Description |
---|---|---|
SolvConstraints | Add | Adds a constraint to the current problem. |
SolvConstraints | AddBounded | Adds a bounded constraint to the current problem. Equivalent to adding both cellRef>=lowBound and cellRef<=highBound |
SolvConstraints | AreSatisfied | Returns True if all model Constraints are satisfied. |
SolvConstraints | Change | Changes a constraint of the current problem. If cellRef AND relation do not match an existing constraint, then use Relax and Add instead. |
SolvConstraints | ChangeBounded | Changes a bounded constraint of the current problem. |
SolvConstraints | Count | Gets the total number of constraints set for the current problem. |
SolvConstraints | Relax | Deletes a constraint from the current problem. |
SolvConstraints | RelaxAll | Deletes all constraints from the current problem. |
SolvConstraints | RelaxBounded | Deletes a bounded constraint from the current problem. |
A class to define the Decision variable, i.e. the cells that are changed in order to satisfy the Objective. Example usage:
Problem.DecisionVars.Add "E10:E14"
Problem.DecisionVars.Initialize 0.2, 0.2, 0.2, 0.2, 0.2
Class | Method/Property | Description |
---|---|---|
SolvDecisionVars | Add | Adds a cell(s) range that will be changed to achieve the desired result in the Objective cell - limited to 200 cells. |
SolvDecisionVars | CellRange | Gets the Decision variable cell range. |
SolvDecisionVars | Count | Gets the total number of Decision variables. |
SolvDecisionVars | Initialize | Initializes Decision Variables to user-specified values - can be a constant to assign to all, or a list of values to assign to each variable. |
SolvDecisionVars | Remove | Removes a cell or range of cells from the Decision variable set |
SolvDecisionVars | RemoveAll | Removes all Decision variables. |
A class to define the Solver Objective function. Example usage:
Problem.Objective.Define "E18", slvMaximize
Class | Method/Property | Description |
---|---|---|
SolvObjective | CellRange | Gets the Objective variable cell value. |
SolvObjective | Define | Sets the Objective (Target) cell and parameters. |
A class to set Solver Options. Example usage:
Problem.Solver.Options.AssumeNonNeg = False
Problem.Solver.Options.RandomSeed = 7
Class | Method/Property | Description |
---|---|---|
SolvOptions | AssumeNonNeg | True to have Solver assume a lower limit of zero for all decision variable cells that do not have explicit lower limits Constraints (the cells must contain nonnegative values). False to have Solver use only the limits specified in the Constraints. |
SolvOptions | Convergence | A number between 0 (zero) and 1 that specifies the convergence tolerance for the GRG Nonlinear Solving and Evolutionary Solving methods. For the GRG method, when the relative change in the target cell value is less than this tolerance for the last five iterations, Solver stops. For the Evolutionary method, when 99% or more of the members of the population have fitness values whose relative (i.e. percentage) difference is less than this tolerance, Solver stops. In both cases, Solver displays the message Solver converged to the current solution. All constraints are satisfied. |
SolvOptions | Derivatives | Specifies forward differencing or central differencing for estimates of partial derivatives of the objective and constraint functions: 1 represents forward differencing, and 2 represents central differencing. Central differencing requires more worksheet recalculations, but it may help with problems that generate a message saying that Solver could not improve the solution. With constraints whose values change rapidly near their limits, you should use central differencing. The default value is 1 (forward differencing). |
SolvOptions | Estimates | Specifies the approach used to obtain initial estimates of the basic variables in each one-dimensional search: 1 represents tangent estimates, and 2 represents quadratic estimates. Tangent estimates use linear extrapolation from a tangent vector. Quadratic estimates use quadratic extrapolation; this may improve the results for highly nonlinear problems. The default value is 1 (tangent estimates). |
SolvOptions | IntTolerance | A decimal number between 0 (zero) and 100 that specifies the Integer Optimality percentage tolerance. This argument applies only if integer constraints have been defined; it specifies that Solver can stop if it has found a feasible integer solution whose objective is within this percentage of the best known bound on the objective of the true integer optimal solution. A larger percentage tolerance would tend to speed up the solution process. |
SolvOptions | MaxIntegerSols | The maximum number of feasible (or integer feasible) solutions Solver will consider in problems with integer constraints, and problems solved via the Evolutionary Solving method. The value must be a positive integer. |
SolvOptions | MaxIterations | The maximum number of iterations Solver will use in solving the problem. The value must be a positive integer. |
SolvOptions | MaxSubproblems | The maximum number of subproblems Solver will explore in problems with integer constraints, and problems solved via the Evolutionary Solving method. The value must be a positive integer. |
SolvOptions | MaxTime | The maximum amount of time (in seconds) Solver will spend solving the problem. The value must be a positive integer. |
SolvOptions | MaxTimeNoImp | When the Evolutionary Solving method is used, the maximum amount of time (in seconds) Solver will continue solving without finding significantly improved solutions to add to the population. The value must be a positive integer. |
SolvOptions | MultiStart | True to have Solver use multistart method for global optimization with the GRG Nonlinear Solving method, when SolverSolve is called. False to have Solver run the GRG Solving method only once, without multistart, when SolverSolve is called. |
SolvOptions | MutationRate | A number between 0 (zero) and 1 that specifies the rate at which the Evolutionary Solving method will make mutations to existing population members. A higher Mutation rate tends to increase the diversity of the population, and may yield better solutions. |
SolvOptions | PopulationSize | The number of different starting points (values for the decision variables) you want the multistart method to consider. The minimum population size is 10; if you supply a value less than 10, or leave it blank, the multistart method uses a population size of 10 times the number of decision variables, but no more than 200. |
SolvOptions | Precision | A number between 0 (zero) and 1 that specifies the precision with which constraints (including integer constraints) must be satisfied. The default precision is 0.000001. A smaller number of decimal places (for example, 0.0001) indicates a lower degree of precision. In general, the higher the degree of precision you specify (the smaller the number), the more time Solver will take to reach solutions. |
SolvOptions | RandomSeed | A positive integer specifies a fixed seed for the random number generator used by the Evolutionary Solving method and the GRG Nonlinear multistart method for global optimization. This means that Solver will find the same solution each time it is run on a model that has not changed. A zero value specifies that Solver should use a different seed for the random number generator each time it runs, which may yield different solutions each time it is run on a model that has not changed. |
SolvOptions | RequireBounds | True to cause the Evolutionary Solving method and the multistart method to return immediately from a call to SolveIt with a value of 18 if any of the variables do not have both lower and upper bounds defined. False to have these methods attempt to solve the problem without bounds on all of the variables. |
SolvOptions | Reset | Resets all Option values to defaults. |
SolvOptions | Scaling | If the objective or constraints differ by several orders of magnitude - for example, maximizing percentage of profit based on million-dollar investments - set this option True to have Solver internally rescale the objective and constraint values to similar orders of magnitude during computation. If this option is False, Solver will perform its computations with the original values of the objective and constraints. The default value is True. |
SolvOptions | SearchOption | Use the Search options to specify the search algorithm that will be used at each iteration to decide which direction to search in: 1 represents the Newton search method, and 2 represents the conjugate search method. Newton, which uses a quasi-Newton method, is the default search method. |
SolvOptions | SolveWithout | True to have Solver ignore any integer constraints and solve the relaxation of the problem. False to have Solver use the integer constraints in solving the problem. |
SolvOptions | StepThru | True to have Solver pause on each trial solution. The default value is False. |
The main class to define the Solver problem, including Objective, Decision Variables, and Constraints. Example usage:
Dim problem as SolvProblem
Dim ws as Worksheet
Set ws = ActiveWorkbook.Worksheets("my worksheet")
Set Problem = New SolvProblem
Problem.Initialize ws
Class | Method/Property | Description |
---|---|---|
SolvProblem | AfterSolve | Fires on each solution trial iteration to allow user to perform intermediate processing. |
SolvProblem | BeforeSolve | Fires on each solution trial iteration to allow user to perform intermediate processing. |
SolvProblem | CleanUp | Cleans the problem worksheet of all solver associated info. |
SolvProblem | Constraints | Exposes the Constraints object. |
SolvProblem | DecisionVars | Exposes the DecisionVars object. |
SolvProblem | Initialize | Initializes the problem - this must be called before all other methods. |
SolvProblem | Objective | Exposes the Objective object. |
SolvProblem | Reset | Resets the problem objective and decision variables without affecting the solver options. |
SolvProblem | SaveSolutionsToArray | Returns a Variant array containing all intermediate (trial) and final solutions, as well as a flag indicating whether each solution passed all problem contraints. |
SolvProblem | SaveSolutionsToRange | Saves all intermediate and final solutions to the given Worksheet Range. |
SolvProblem | ShowTrial | Fires on each solution trial iteration to allow user to perform intermediate processing. |
SolvProblem | SolveIt | Solves the currently defined problem. Returns the Solver result code. |
SolvProblem | Solver | Exposes the Solver object. |
SolvProblem | SolverSheet | Returns a reference to the current problem Worksheet |
A class to manage Solver Engine and Options. Example usage:
Problem.Solver.Method = slvGRG_Nonlinear
Class | Method/Property | Description |
---|---|---|
SolvSolver | EnableEvents | Enables the ShowTrial, BeforeSolve, AfterSolve events of the SolvProblem class (default = False). |
SolvSolver | Method | Sets/Gets the solver method (engine) to use to solve the problem. |
SolvSolver | MsgCodeToString | Returns the string message associated with the Solver code returned by SolveIt method. |
SolvSolver | Options | Exposes the Solver Options object. |
SolvSolver | Reset | Resets all Option values to defaults. |
SolvSolver | SaveAllTrialSolutions | Sets whether all intermediate solutions attempted should be saved - see GetAllSolutions to return solution array. |
SolvSolver | UserCallbackMacroName | Sets the name of the user-defined callback function that will be called on each trial solution. If this is used in conjunction with th ShowTrial event, then the return value from the callback function takes precedence over the return value from the event. |