Initializing help system before first use

Local solutions


Type: Programming
Rating: 2 (easy-medium)
Description: Nonlinear example demonstrating the presence of locally optimal solutions, and the role of initial points
File(s): xnlp_local_optima.mos


xnlp_local_optima.mos
! XNLP example demonstrating the presence of locally optimal solutions, and the 
! role of initial points
!
! This example performs a series of solves for the exact same problem having 
! several local optimas
!
! 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-2025 Fair Isaac Corporation
!       author: Zsolt Csizmadia
model mmxnlp_nlp_duals
uses "mmxnlp"; 

declarations
 x,y: mpvar
end-declarations

!setparam("xnlp_verbose",1)

! A function with several local valleys
x^2*sin(x) >= y

! Observe the regions of attractions
setparam("XPRS_NLPSOLVER",1)
writeln("Locally optimal solutions found:")	
writeln("------------------------------------------")
writeln("        x            y         objective  ")
writeln("------------------------------------------")
forall (i in -5..40) do
	setinitval(x,i)
	setinitval(y,i)
	minimize(x+y)
	if (getparam("xnlp_nlpstatus") = XNLP_STATUS_LOCALLY_OPTIMAL) then
		writeln(strfmt(getsol(x),13),",",strfmt(getsol(y),13),": ",
		        strfmt(getobjval,13))
    else
		writeln("Status is not locally optimal")	
	end-if
end-do

writeln("Global Optimum:")
setparam("XPRS_NLPSOLVER",2)
minimize(x+y)
if (getparam("xnlp_nlpstatus") = XNLP_STATUS_OPTIMAL) then
		writeln(strfmt(getsol(x),13),",",strfmt(getsol(y),13),": ",
		        strfmt(getobjval,13))
    else
		writeln("Status is not globally optimal")	
	end-if

end-model


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