Initializing help system before first use

Nonlinear Programming


Type: Nonlinear
Rating: 2 (easy-medium)
Description:
  • airport.mos, airport_graph.mos: QCQP problem (requires airport.dat); user graph drawing
  • fin_nl.mos: Nonlinear problem (determine interest rates over multiple time periods)
File(s): airport.mos, airport_graph.mos, fin_nl.mos
Data file(s): airport.dat


airport.mos
(!*********************************************************************
   Mosel NL examples
   =================
   file airport.mos
   ````````````````
   Locate N airports each within a specified distance of a 
   city centre, and minimise the sum of square of the distances 
   between all the airports.

   QCQP problem.
  
   Based on AMPL model airport.mod by Hande Y. Benson
   Source: http://www.orfe.princeton.edu/~rvdb/ampl/nlmodels/cute/ 
   Reference: 
   Rodrigo de Barros Nabholz & Maria Aparecida Diniz Ehrhardt
   November 1994, DMA - IMECC- UNICAMP.

   (c) 2008 Fair Issac Corporation
       author: S. Heipcke, May 2008, rev. Mar. 2013
*********************************************************************!)

model "airport (QPQC)"
 uses "mmxprs", "mmnl"

 declarations
  RN: range                      ! Set of airports
  R: array(RN) of real           ! Square of max. distance to given location
  CX,CY: array(RN) of real       ! Target location for each point
  x,y: array(RN) of mpvar        ! x-/y- coordinates
  LimDist: array(RN) of nlctr
 end-declarations

 initialisations from "airport.dat"
  CY  CX  R
 end-initialisations

! Set bounds on variables
 forall(i in RN) do
  -10<=x(i); x(i)<=10
  -10<=y(i); y(i)<=10
 end-do

! Objective: minimise the total squared distance between all points
 TotDist:= sum(i,j in RN | i<j) ((x(i)-x(j))^2+(y(i)-y(j))^2)

! Constraints: all points within given distance of their target location
 forall(i in RN) 
  LimDist(i):= (x(i)-CX(i))^2+(y(i)-CY(i))^2 <= R(i)

(! For exporting the matrix file
 setparam("XPRS_loadnames", true)
 loadprob(TotDist)
 writeprob("airport.mat","l")
!)

 setparam("XPRS_verbose", true);
 minimise(TotDist);

 writeln("Solution: ", getobjval);
 forall(i in RN) writeln(i, ": ", getsol(x(i)), ", ", getsol(y(i)))

end-model

airport_graph.mos
(!*********************************************************************
   Mosel NL examples
   =================
   file airport.mos
   ````````````````
   Locate N airports each within a specified distance of a 
   city centre, and minimise the sum of square of the distances 
   between all the airports.

   QCQP problem.
  
   Based on AMPL model airport.mod by Hande Y. Benson
   Source: http://www.orfe.princeton.edu/~rvdb/ampl/nlmodels/cute/ 
   Reference: 
   Rodrigo de Barros Nabholz & Maria Aparecida Diniz Ehrhardt
   November 1994, DMA - IMECC- UNICAMP.

   (c) 2008 Fair Issac Corporation
       author: S. Heipcke, May 2008, rev. Sep. 2017
*********************************************************************!)

model "airport (QPQC)"
 uses "mmxprs", "mmnl", "mmsvg"

 declarations
  RN: range                      ! Set of airports
  R: array(RN) of real           ! Square of max. distance to given location
  CX,CY: array(RN) of real       ! Target location for each point
  x,y: array(RN) of mpvar        ! x-/y-coordinates to determine
 end-declarations

 initialisations from "airport.dat"
  CY  CX  R
 end-initialisations

! Set bounds on variables
 forall(i in RN) do
  -10<=x(i); x(i)<=10
  -10<=y(i); y(i)<=10
 end-do

! Objective: minimise the total squared distance between all points
 TotDist:= sum(i,j in RN | i<j) ((x(i)-x(j))^2+(y(i)-y(j))^2)

! Constraints: all points within given distance of their target location
 forall(i in RN) 
  LimDist(i):= (x(i)-CX(i))^2+(y(i)-CY(i))^2 <= R(i)

 setparam("XPRS_verbose", true);
 minimise(TotDist);

 writeln("Solution: ", getobjval);
 forall(i in RN) writeln(i, ": ", getsol(x(i)), ", ", getsol(y(i)))

! **** Display the solution as user graph ****
 
! Scale the size of the displayed graph
 svgsetgraphscale(50)
 svgsetgraphpointsize(3)
 svgsetgraphstyle(SVG_STROKEWIDTH,3)

! Draw the target locations
 svgaddgroup("T", "Target area", SVG_SILVER)
 svgsetstyle(SVG_FILL,SVG_CURRENT)
 forall(i in RN) svgaddcircle(CX(i), CY(i), sqrt(R(i)))

! Draw the solution points
 svgaddgroup("S", "Solution", SVG_BLUE)
 forall(i in RN) svgaddpoint(x(i).sol, y(i).sol)
 
! Update the display
 svgrefresh
 svgsave("airport.svg")
 svgwaitclose("Close browser window to terminate model execution.", 1)

end-model

fin_nl.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file fin_nl.mos 
   ```````````````
   Financial application solved by SLP.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, June 2003, rev. Feb. 2013
*******************************************************!)

model "Recursion (NLP)"
 uses "mmxnlp"                       ! Use Xpress NonLinear

 declarations
  NT=6                               ! Time horizon
  QUARTERS=1..NT                     ! Range of time periods
  M,P,V: array(QUARTERS) of real     ! Payments

  interest: array(QUARTERS) of mpvar ! Interest
  net: array(QUARTERS) of mpvar      ! Net
  balance: array(QUARTERS) of mpvar  ! Balance
  rate: mpvar                        ! Interest rate
 end-declarations

 M:: [-1000, 0, 0, 0, 0, 0]
 P:: [206.6, 206.6, 206.6, 206.6, 206.6, 0]
 V:: [-2.95, 0, 0, 0, 0, 0]
                                     
 setinitval(rate, 0)                 ! Set initial values for variables
 forall(t in QUARTERS) setinitval(balance(t), 1)

                                     ! net = payments - interest
 forall(t in QUARTERS) net(t) = (M(t)+P(t)+V(t)) - interest(t)	

                                     ! Money balance across periods
 forall(t in QUARTERS) balance(t) = if(t>1, balance(t-1), 0) - net(t)	
                                     
                                     ! Interest rate                          
 forall(t in 2..NT) -(365/92)*interest(t) + balance(t-1) * rate = 0
                          
 interest(1) = 0                     ! Initial interest is zero
 forall (t in QUARTERS) net(t) is_free
 forall (t in 1..NT-1) balance(t) is_free
 balance(NT) = 0                     ! Final balance is zero

 ! setparam("XNLP_VERBOSE",true)     ! Uncomment to see detailed output
 setparam("XNLP_SOLVER", 0)          ! Use the SLP solver

 minimize(0)                         ! Solve the problem (get feasible)
 
                                     ! Print the solution
 writeln("\nThe interest rate is ", getsol(rate))
 write(strfmt("t",5), strfmt(" ",4))
 forall(t in QUARTERS) write(strfmt(t,5), strfmt(" ",3))
 write("\nBalances ")
 forall(t in QUARTERS) write(strfmt(getsol(balance(t)),8,2))
 write("\nInterest ")
 forall(t in QUARTERS) write(strfmt(getsol(interest(t)),8,2))
 writeln

end-model

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.