FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home Pre-emptive and Archimedian goal programming

Description
goalctr.mos: goal programming using constraints
• (un)hiding constraints
• adding and deleting constraint terms
• getting solution information
• case statement
• use of procedures

goalobj.mos: goal programming using objective functions
• changing constraint type
• changing the objective function
Further explanation of this example: 'Mosel User Guide', Section 12.2 Goal Programming

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

goalctr.mos

(!*******************************************************
* Mosel Example Problems                              *
* ======================                              *
*                                                     *
* file goalctr.mos                                    *
*                                     *
* Example for the use of the Mosel language           *
* (Pre-emptive and Archimedian goal programming       *
*  using constraints)                                 *
*                                                     *
* (c) 2008 Fair Isaac Corporation                     *
*     author: S. Heipcke, 2001, rev. Mar. 2006        *
*******************************************************!)

model GoalCtr                       ! Start a new model

uses "mmxprs"                       ! Load the optimizer library

forward procedure preemptive        ! Declare some procedures that are
forward procedure archimedian       ! defined later

declarations
NGOALS=3                           ! Number of goals
x,y: mpvar                         ! Variables
dev: array(1..2*NGOALS) of mpvar   ! Deviation from goals
mindev: linctr                     ! Objective function
goal: array(1..NGOALS) of linctr   ! Goal constraints
end-declarations

limit:= 100*x + 60*y <= 600        ! Define a constraint

! Define the goal constraints
goal(1):=  7*x + 3*y >= 40
goal(2):= 10*x + 5*y = 60
goal(3):=  5*x + 4*y >= 35

! Some declarations for a nice printout
declarations
STypes={CT_GEQ, CT_LEQ, CT_EQ}
ATypes: array(STypes) of string
end-declarations

ATypes(CT_GEQ):= ">="; ATypes(CT_LEQ):= "<="; ATypes(CT_EQ):= "="

preemptive                         ! Pre-emptive goal programming
archimedian                        ! Archimedian goal programming

!***********************************************************************

procedure printsol

forall(g in 1..NGOALS)
if(dev(2*g).sol>0) then
writeln(" Goal(",g,") deviation from target: -", dev(2*g).sol)
elif(dev(2*g-1).sol>0) then
writeln(" Goal(",g,") deviation from target: +", dev(2*g-1).sol)
end-if

end-procedure

!***********************************************************************

procedure preemptive

writeln("Pre-emptive:")

(!
Add successively the goals to the problem and solve it, until all
goals have been added or a goal cannot be satisfied. This assumes that
the goals are given ordered by priority.
!)

! Remove (=hide) goal constraint from the problem
forall(i in 1..NGOALS) goal(i).hidden:=true

i:=0
while (i<NGOALS) do
i+=1
goal(i).hidden:=false           ! Add (=unhide) the next goal
case goal(i).type of            ! Add deviation variable(s)
CT_GEQ: do
deviation:= dev(2*i)
mindev += deviation
end-do
CT_LEQ: do
deviation:= -dev(2*i-1)
mindev += dev(2*i-1)
end-do
CT_EQ : do
deviation:= dev(2*i) - dev(2*i-1)
mindev += dev(2*i) + dev(2*i-1)
end-do
else    writeln("Wrong constraint type")
break
end-case
goal(i)+= deviation

minimize(mindev)                ! Solve the LP-problem
writeln(" Solution(", i,"): x: ", x.sol, ", y: ", y.sol)

goal(i)-= deviation             ! Remove deviation variable(s) from goal
if(getobjval>0) then
writeln("Cannot satisfy goal ",i)
break
end-if
end-do

! Solution printout
writeln(" Goal", strfmt("Target",12), strfmt("Value",9))
forall(g in 1..i)
writeln(strfmt(g,5), strfmt(ATypes(goal(g).type),3),
strfmt(-goal(g).coeff,9),
strfmt( goal(g).act-dev(2*g).sol+dev(2*g-1).sol ,9))

printsol

end-procedure

!***********************************************************************

procedure archimedian

writeln("\nArchimedian:")

declarations
Penalty: array(1..NGOALS) of real ! Penalties for goal constraints
end-declarations

Penalty:: [8, 3, 1]

mindev:=0                         ! Re-initialize objective function

! Define the objective as weighted sum of the deviation variables
forall(g in 1..NGOALS) do
case goal(g).type of            ! Add deviation variable(s)
CT_GEQ: do
deviation:= dev(2*g)
mindev += Penalty(g)*deviation
end-do
CT_LEQ: do
deviation:= -dev(2*g-1)
mindev += Penalty(g)*dev(2*g-1)
end-do
CT_EQ : do
deviation:= dev(2*g) - dev(2*g-1)
mindev += Penalty(g)*(dev(2*g) + dev(2*g-1))
end-do
else    writeln("Wrong constraint type")
break
end-case
goal(g)+= deviation
end-do

minimize(mindev)                  ! Solve the LP-problem
writeln(" Solution: x: ", x.sol, ", y: ", y.sol)

! Solution printout
writeln(" Goal", strfmt("Target",12), strfmt("Value",9), strfmt("Penalty",9))
forall(g in 1..NGOALS)
writeln(strfmt(g,5), strfmt(ATypes(goal(g).type),3),
strfmt(-goal(g).coeff,9),
strfmt( goal(g).act-dev(2*g).sol+dev(2*g-1).sol ,9),
strfmt(Penalty(g),9))

printsol

end-procedure

end-model
{"ft_lang_label":"__label__en","ft_lang_prob":0.5594055,"math_prob":0.836324,"size":4327,"snap":"2022-05-2022-21","text_gpt3_token_len":1214,"char_repetition_ratio":0.209808,"word_repetition_ratio":0.06870229,"special_character_ratio":0.37462446,"punctuation_ratio":0.215311,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9728519,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-26T17:58:44Z\",\"WARC-Record-ID\":\"<urn:uuid:49ec20d9-7c35-41cf-b6c8-456ccd040db7>\",\"Content-Length\":\"20450\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:063cd7ca-7749-491b-8813-1cb5b138afa5>\",\"WARC-Concurrent-To\":\"<urn:uuid:d75d37e7-c7da-4d38-ade7-e3ddaae6d043>\",\"WARC-IP-Address\":\"45.60.151.61\",\"WARC-Target-URI\":\"https://examples.xpress.fico.com/example.pl?id=goalctr\",\"WARC-Payload-Digest\":\"sha1:EKIEN5JQNSGKXVA7264RAAYMQB2FIMKN\",\"WARC-Block-Digest\":\"sha1:HH4TKIL2Z3K52BB4AMESDAGUUY5T2SUP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662619221.81_warc_CC-MAIN-20220526162749-20220526192749-00044.warc.gz\"}"}