FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious example

Local authorities and public services

Description
Problem name and type, featuresDifficultyRelated examples
J‑1 Water conveyance / water supply management: Maximum flow problem ** j1water_graph.mos, g1rely.mos
encoding of arcs, selection with `|', record data structure
J‑2 CCTV surveillance: Maximum vertex cover problem ** j2bigbro_graph.mos, g6transmit.mos, d5cutsh.mos
encoding of network, exists
J‑3 Rigging elections: Partitioning problem **** j3elect_graph.mos, partitioning_graph.mos
algorithm for data preprocessing; file inclusion, 3 nested/recursive procedures, working with sets, if-then, forall-do, exists, finalize
J‑4 Gritting roads: Directed Chinese postman problem **** j4grit_graph.mos
algorithm for finding Eulerian path/graph for printing; encoding of arcs, dynamic array, exists, 2 functions implementing Eulerian circuit algorithm, round, getsize, break, while-do, if-then-else, list handling
J‑5 Location of income tax offices: p-median problem ****
modeling an implication, all-pairs shortest path algorithm (Floyd-Warshall); dynamic array, exists, procedure for shortest path algorithm, forall-do, if-then, selection with `|'
J‑6 Efficiency of hospitals: Data Envelopment Analysis (DEA) ***
description of DEA method; loop over problem solving with complete re-definition of problem every time, naming and declaring constraints


Further explanation of this example: 'Applications of optimization with Xpress-MP', Chapter 15: Local authorities and public services

mosel_app_10.zip[download all files]

Source Files

Data Files





j3elect.mos

(!******************************************************
   Mosel Example Problems
   ======================

   file j3elect.mos
   ````````````````
   Grouping quarters to election districts

   For elections, a capital is divided into zones called
   quarters. For each quarter, we know the forecasted number
   of favorable votes for a particular candidate and the total
   number of electors. An electoral district is formed by
   several adjacent quarters that must have between a minimum
   and a maximum number of voters. Determine a partitioning
   into five electoral districts that maximizes the number
   of seats for the candidate.

   This partitioning problem asks for a subset of electoral
   districts such that every quarter appears in a single chosen
   electoral district. The Mosel implementation is divided into
   the data preprocessing and the model itself. After data arrays
   declaration, the included file j3elect_calc.mos generates the data
   in the form required for the model. Function 'getprobstat'
   is used to test the optimization status.

   (c) 2008-2022 Fair Isaac Corporation
       author: S. Heipcke, Apr. 2002, rev. Mar. 2022
*******************************************************!)

model "J-3 Rigging elections"
 uses "mmxprs"

 parameters
  REQD = 6                            ! Required number of districts
 end-parameters

 declarations
  QUARTERS = 1..14                    ! Number of quarters
  RDIST: range                        ! Set of election districts
  
  MAJ: array(RDIST) of integer        ! 1 if majority of votes, 0 otherwise
  DISTR: array(RDIST,QUARTERS) of integer  ! 1 if quarter is in district,
                                           ! 0 otherwise
 end-declarations

 include "j3elect_calc.mos"

 declarations
  choose: array(RDIST) of mpvar      ! 1 if district chosen, 0 otherwise
 end-declarations

! Objective: number of votes
 Votes:= sum(d in RDIST) MAJ(d)*choose(d)

! Partitioning
 forall(q in QUARTERS) sum(d in RDIST) DISTR(d,q)*choose(d) = 1
 
! Desired number of districts
 sum(d in RDIST) choose(d) = REQD

 forall(d in RDIST) choose(d) is_binary

! Solve the problem
 maximize(Votes)
 
! Solution printing
 if(getprobstat<>XPRS_OPT) then
  writeln("Problem is infeasible")
 else 
  writeln("Total number of votes: ", getobjval)
  forall(r in RDIST | getsol(choose(r))>0) do
   write(r, ": ")
   forall(q in QUARTERS | DISTR(r,q)>0) write(" ", q)
   writeln(" (", MAJ(r), ")") 
  end-do
 end-if
  
end-model

Back to examples browserPrevious example