ipo interior-point optimisation library

Links

Home ·
Download ·
Documentation ·
Namespaces and #includes ·
Defining functions ·
Example of a function ·
Variables and arrays ·
Objective and constraints ·
Building a model ·
Example ·
Bugs ·

Example of an ipo model.

This is an example of a quadratically constrained linear optimisation problem. There are further test examples in the test directory of the source code.

#include<fstream>
#include<ipo/Model.hpp>
#include<ipo_function/concrete/QuadraticCombination.hpp>

int main(){
  using namespace ipo;
  Model model;
  
  ipo_function::concrete::QuadraticCombination quadraticCombination { 2 };
  quadraticCombination.setCoefficient( 0, 8.592 );
  quadraticCombination.setCoefficient( 1, 3.448 );
  quadraticCombination.setCoefficient( 0, 1, 2.963 );
  
  Objective objective { model, quadraticCombination, "8.952x2 + 2.963xy + 3.448y2" };
  Variable x { model, "x" };
  Variable y { model, "y" };
  x.setLowerBound( 0 );
  y.setLowerBound( 0 );
  objective.addVariable( x );
  objective.addVariable( y );
  model.setObjective( objective );

  ipo_function::concrete::LinearCombination linearCombination { 2 };
  linearCombination.setCoefficient( 0, 0.696 );
  linearCombination.setCoefficient( 1, 0.322 );
  Constraint constraint { model, linearCombination, "0.696x + 0.322y" };
  constraint.addVariable( x );
  constraint.addVariable( y );
  constraint.setLowerBound( 0.5 );
  model.addConstraint( constraint );

  model.getParameters().setOutputStream( &std::cout );
  
  model.minimise();

  std::cout << "x = " << x.getValue() << std::endl;
  std::cout << "y = " << y.getValue() << std::endl;

  gsl::vector v( 2 );
  v[0] = x.getValue();
  v[1] = y.getValue();
  std::cout << quadraticCombination( v ) << std::endl;

  std::cout << std::endl;
  std::cout << "Solution to: minimise" << std::endl;
  std::cout << "  " << objective.getName() << std::endl;
  std::cout << "subject to" << std::endl;
  std::cout << "  " << constraint.getName() << " ≥ "
	    << constraint.getLowerBound() << std::endl;
  std::cout << "and" << std::endl;
  std::cout << "  " << x.getName() << " ≥ " << x.getLowerBound() << std::endl;
  std::cout << "  " << y.getName() << " ≥ " << x.getLowerBound() << std::endl;
  std::cout << std::endl;

  exit( 0 );
}


Last modified: Tue 02 Jul 2013 04:56 pm

SourceForge.net Logo