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Ū Procedural 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 Procedural API.  Click the links below to see example MATLAB code written using the SDK's other APIs.

bulletMATLAB Object-Oriented API
bulletMATLAB Optimization Toolbox API

To solve a constrained nonlinear optimization problem using the Procedural 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.

function ret = EvaluateCallback(prob, refuser, evaltype)
   var = SolverSDK('VarValue', prob, 'MyVars');
   fcn = [0 0];
   fcn(1) = var(1) + var(2); % x1 + x1 = 1
   fcn(2) = var(1) * var(2); % x1 * x2 >= 0
   obj = var(1)*var(1) + var(2)*var(2); % objective
   SolverSDK('FcnValueSet', prob, 'MyCons', fcn);
   SolverSDK('FcnValueSet', prob, 'MyObj', obj);
   ret = 'Continue';
end

You call functions to create a Problem object, and add this Evaluator to the Problem object's collection of Evaluators.  In this example, we specify constraints with "right hand sides" and "relations" (<=, =, >=).  The SDK offers several ways to specify constraints -- another way is shown in the Object-Oriented API example code.

For any type of optimization problem, you simply call SolverSDK ('SolverOptimize', prob).  All errors are reported by raising exceptions, which will cause the catch clause to be executed.

rhs = [1 0];
rel = {['EQ'] ['GE']};
try
   prob = SolverSDK('Problem');
   SolverSDK('ProbTypeSet', prob, 'Minimize', 'OptNLP');
   SolverSDK('VariableAdd', prob, 'MyVars', 'Decision', 2);
   SolverSDK('FunctionAdd', prob, 'MyCons', 'Constraint', 2);
   SolverSDK('FunctionAdd', prob, 'MyObj', 'Objective', 1);
   SolverSDK('FcnRelation', prob, 'MyCons', rel, rhs);
   SolverSDK('EvaluatorAdd', prob, 'EvaluateCallback',
      '', 'Function');
   [status, objval] = SolverSDK('SolverOptimize', prob);
   x = SolverSDK('VarFinalValue', prob, 'MyVars');
catch
   errstr = lasterror;
   disp(errstr.message);
end
if prob ~= 0
   SolverSDK('ProbFree', prob);
end

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