(!********************************************************************* Mosel Example Problems ====================== file assignment.mos ``````````````````` TYPE: Assignment problem DIFFICULTY: 1 FEATURES: simple LP problem, graphical representation of results DESCRIPTION: A set of projects is assigned to persons with the objective to maximize the overall satisfaction. A preference rating per person and project is given. In this model formulation the solution to the LP problem is integer, there is no need to define the decision variables explicitly as binaries. FURTHER INFO: Similar problems: `Applications of optimization with Xpress-MP', Section 11.1 `Flight connections at a hub', Section 14.1 `Assigning personnel to machines' Section 8.6 `Assignment of production batches to machines' (c) 2004 Dash Associates author: S. Heipcke **********************************************************************!) model Assignment uses "mmxprs", "mmive" declarations NP = 5 ! Number of persons/projects RP = 1..NP ! Set (range) of persons/projects PREF: array(RP,RP) of integer ! Preference values assign: array(RP,RP) of mpvar ! Assignment person-project end-declarations PREF:= [1, 2, 3, 5, 4, 3, 2, 5, 4, 1, 3, 4, 1, 5, 2, 4, 3, 2, 5, 1, 2, 3, 5, 4, 1] ! Objective function: maximize satisfaction Satisfaction:= sum(m,p in RP) PREF(m,p)*assign(m,p) ! One person per project forall(p in RP) OnePersProj(p):= sum(m in RP) assign(m,p)=1 ! One project per person forall(m in RP) OneProjPers(m):= sum(p in RP) assign(m,p)=1 ! Solve the problem maximize(Satisfaction) ! Solution printing writeln("Total satisfaction score: ", getobjval) forall(m in RP) writeln("Person ", m, ": project ", getsol(sum(p in RP) p*assign(m,p)) ) ! Solution drawing IVEzoom(0,0,3,NP+1) PersGraph:= IVEaddplot("Persons", IVE_BLUE) ProjGraph:= IVEaddplot("Projects", IVE_RED) AsgnGraph:= IVEaddplot("Assignments", IVE_BLACK) forall(m in RP) do IVEdrawpoint(PersGraph, 1, m) IVEdrawlabel(PersGraph, 0.8, m, string(m)) a:=getsol(sum(p in RP) p*assign(m,p)) IVEdrawline(AsgnGraph, 1, m, 2, a) IVEdrawlabel(AsgnGraph, 1.2, (5*m+a)/6, string(PREF(m,round(a)))) end-do forall(p in RP) do IVEdrawpoint(ProjGraph, 2, p) IVEdrawlabel(ProjGraph, 2.2, p, string(p)) end-do end-model