Initializing help system before first use

Numerical differentation and accuracy


Type: Programming
Rating: 2 (easy-medium)
Description: Nonlinear example demonstrates the solver sensitibility to errors introduced by finite differences
File(s): xnlp_solvers_numerical_derivatives.mos


xnlp_solvers_numerical_derivatives.mos
! This example demonstrates the solver sensitibility to errors introduced by 
! numerical derivatives 
!
! This model should be run twice, with different settings for XNLP_SOLVER
! This example is a version of the Polygon4 example.
! 
! This example demonstrates a particular non-linear optimization concept as related 
! to Xpress NonLinear.
! The version of the example is for Xpress 7.5.
!
!  (c) 2013 Fair Isaac Corporation
 
model "Polygon 4"
 uses "mmxnlp"

 parameters
  N=5                               ! Number of vertices
  SOLVER=0                          ! 0: SLP, 1: Knitro
 end-parameters
 
 declarations
  RN = 1..N
  Area: nlctr
  rho : array(RN) of mpvar          ! Distance of vertex from the base point 
  theta : array(RN) of mpvar        ! Angle from x-axis
  D: array(RN,RN) of nlctr          ! Limit on side length
  FunctionArg: list of nlctr        ! User function arguments
  AreaFunction: userfunc            ! User function definition
 end-declarations

! Objective: sum of areas. Definition of a user function
 AreaFunction := userfuncExcel("polygonsheet.xls", "Sheet1")

! Create function arguments
! Excel functions use their first columns as input: use a list to ensure correct order
 forall (i in 1..N-1) do
  FunctionArg += [nlctr(rho(i))]
  FunctionArg += [nlctr(theta(i))]
 end-do

! Use the Excel user function in a formula for the objective
 Area := F(AreaFunction,FunctionArg)

! Bounds and start values for decision variables
 forall (i in 1..N-1) do
  rho(i) >= 0.1
  rho(i) <= 1
  setinitval(rho(i),4*i*(N + 1 - i)/((N+1)^2))
  setinitval(theta(i),M_PI*i/N)
 end-do
 
! Third side of all triangles <= 1
 forall (i in 1..N-2, j in i+1..N-1) 
  D(i,j) := rho(i)^2 + rho(j)^2 - rho(i)*rho(j)*2*cos(theta(j)-theta(i)) <= 1
 
! Vertices in increasing order 
 forall (i in 2..N-1) theta(i) >= theta(i-1) +.01
 
! Boundary conditions (last vertex above x-axis)
 theta(N-1) <= M_PI

! Uncomment to display user function info
! userfuncinfo(AreaFunction)

! Optional parameter settings
 setparam("xnlp_verbose", true)         ! Enable XNLP output log
 setparam("xnlp_solver", SOLVER)        ! Select the solver
 setparam("xslp_excelvisible", true)

! Solve the problem
 maximise(Area)

! Solution output
 writeln("Area = ", getobjval)
 forall (i in 1..N-1)
  writeln("V",i,": r=",getsol(rho(i))," theta=",getsol(theta(i)))

end-model
 

© 2001-2019 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.