excel solver
optimization
simulation
MATLAB, API, optimization

   solver.com

Frontline Systems, Inc.  

quadratic programming, portfolio optimization, quadratic solver 
Developers of Your Spreadsheet's Solver  
robust optimization, stochastic programming, simulation optimization
   

Solver Platform SDK - MATLABŪ Object-Oriented API


optimization, solver, Excel

 
Home
Register
What's New
Solver Tutorial
Solver Technology
Select a Product
Excel Users
MATLAB Users
Developers
Government Users
Academic Users
Press/Analysts
Privacy Policy
 

 

 
This page illustrates how you can solve the following constrained nonlinear optimization problem:

Minimize
   x1*x1 + x2*x2
Subject to:
   x1 + x2 = 1
   x1 * x2 >= 0
   0 <= x1, x2 <= 1

using the Solver Platform SDK with its MATLAB Object-Oriented API.  Click the links below to see example MATLAB code written using the SDK's other APIs.

bulletMATLAB Procedural API
bulletMATLAB Optimization Toolbox API

To solve a constrained nonlinear optimization problem using the Object-Oriented API, you must write a MATLAB function (called an Evaluator in the terminology of the SDK) that computes values for the objective and constraints.  You can access a wide range of information about the problem and the current state of the solution in this Evaluator, and signal whether the SDK should continue or terminate the solution process early.  The MATLAB code below closely resembles the code you'd write to solve the same problem in C++, C# or Java.

function ret = NLPEvaluator(evaluator)
   var = evaluator.Problem.VarDecision.Value;
   fcn = evaluator.Problem.FcnConstraint.Value;
   idx = evaluator.Problem.ObjectiveIndex; 
   fcn(1) = var(1) + var(2); % x1 + x1 = 1
   fcn(2) = var(1) * var(2); % x1 * x2 >= 0
   evaluator.Problem.FcnConstraint.Value = fcn;
   evaluator.Problem.FcnObjective.Value(idx) =
      var(1)*var(1) + var(2)*var(2); % objective
   ret = 'Continue';
end

You create a Problem object, and add this Evaluator to the Problem object's collection of Evaluators.  In this example, we set properties to specify the lower and upper bounds we need for the constraints, thereby defining both inequalities and equalities.  The SDK offers several ways to specify constraints -- another way is shown in the Procedural API example code.

For any type of optimization problem, you simply call Optimize.  All errors are reported by raising exceptions, which will cause the catch clause to be executed.

try
   problem = Problem('Maximize', 2, 2);
   problem.FcnConstraint.UpperBound = [ 1 1E+30 ];
   problem.FcnConstraint.LowerBound = [ 1 0 ];
   problem.VarDecision.UpperBound = [ 1 1 ];
   problem.VarDecision.LowerBound = [ 0 0 ];
   problem.ProblemType = 'OptNLP';
   problem.Evaluators('Function').Evaluator = 'NLPEvaluator';
   Optimize(problem.Solver); % solve problem
   x = problem.VarDecision.FinalValue;
catch
   errstr = lasterror;
   disp(errstr.message);
end
if isa(problem, 'Problem')
   Destroy(problem);
end

For further information and an example of a mixed-integer linear programming problem written in the SDK's Object-Oriented API for MATLAB, C++, C#, Visual Basic, VB.NET, and Java, click Solver Platform SDK Language/OS Support.  

Back to MATLAB API Overview 

Back to MATLAB Users Start Here

To Learn More:
For instant access to example models, full-text User Guides, and to download free 15-day trial versions of our software products whenever you're ready, you can register now.
User Type
Email Address
Name First Last
Company University
Phone

Trial version passwords are sent to the above email address: See Privacy Policy.
Our Premium Solver Platform works with existing Excel Solver models, solves much larger problems up to hundreds of times faster, and solves new kinds of problems via Evolutionary Solver.  Solver Engines plug into the Premium Solver Platform.
   
Solver Platform SDK makes it easy to solve any type or size of optimization problem in your Visual Basic, VB.NET, C/C++, C#, Java, or MATLAB program. And it's easy to deploy your application with our flexible licensing for software vendors and corporate developers.
   
spreadsheet solver
scarce resources