| (!*********************************************************************
   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 | 
| (!*********************************************************************
   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 | 
| (!******************************************************
   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
 |