(!******************************************************
Mosel User Guide Example Problems
=================================
file transport_insight.mos
``````````````````````````
Solution display in Insight application.
(c) 2012 Fair Isaac Corporation
author: S.Heipcke, Sep. 2012, rev. June 2019
*******************************************************!)
model "Transport"
uses "mmxprs", "mmsystem"
uses "mminsight"
version 1.0.1
!@insight.manage=input
public declarations
!@insight.alias Customer regions
REGION: set of string ! Set of customer regions
!@insight.alias Plants
PLANT: set of string ! Set of plants
!@insight.alias Demand
DEMAND: array(REGION) of real ! Demand at regions
!@insight.alias Production capacity
PLANTCAP: array(PLANT) of real ! Production capacity at plants
!@insight.alias Unit production cost
PLANTCOST: array(PLANT) of real ! Unit production cost at plants
!@insight.alias Capacity on each route
TRANSCAP: dynamic array(PLANT,REGION) of real
! Capacity on each route plant->region
!@insight.alias Distance per route
DISTANCE: dynamic array(PLANT,REGION) of real
! Distance of each route plant->region
!@insight.alias Fuel cost per unit distance
FUELCOST: real ! Fuel cost per unit distance
!@insight.update.afterexecution=true
! @insight.hidden=true
SELCUST: array(REGION) of boolean ! Customer selection for display
! @insight.hidden=true
!@insight.update.afterexecution=true
CURRENTPLANT: string ! Plant selection for display
end-declarations
!@insight.manage=result
public declarations
!@insight.alias Production capacity limits
MaxCap: array(PLANT) of linctr ! Capacity constraints
!@insight.alias Amount shipped
flow: dynamic array(PLANT,REGION) of mpvar ! Flow on each route
RunDate: string ! Date for display
!@insight.hidden=true
MincostSol: real
!@insight.hidden=true
pltotal: array(PLANT) of real !@insight.alias Total
!@insight.hidden=true
rgtotal: array(REGION) of real
end-declarations
! Data input from file
procedure readdata
initializations from 'transprt.dat'
DEMAND
[PLANTCAP,PLANTCOST] as 'PLANTDATA'
[DISTANCE,TRANSCAP] as 'ROUTES'
FUELCOST
end-initializations
end-procedure
! Data input (from file or Insight scenario data)
case insightgetmode of
INSIGHT_MODE_LOAD: do
readdata ! Initialize data for baseline
exit(0) ! Stop model run after data input
end-do
INSIGHT_MODE_RUN:
insightpopulate ! Inject scenario data and continue
INSIGHT_MODE_NONE:
readdata ! Non-Insight runs: initialize data and continue
else
writeln_("Unknown run mode")
exit(1)
end-case
!@insight.resultdata.delete=on-execute
! Create the flow variables that exist
forall(p in PLANT, r in REGION | exists(TRANSCAP(p,r)) ) create(flow(p,r))
! Objective: minimize total cost
MinCost:= sum(p in PLANT, r in REGION | exists(flow(p,r)))
(FUELCOST * DISTANCE(p,r) + PLANTCOST(p)) * flow(p,r)
! Limits on plant capacity
forall(p in PLANT) MaxCap(p):= sum(r in REGION) flow(p,r) <= PLANTCAP(p)
! Satisfy all demands
forall(r in REGION) sum(p in PLANT) flow(p,r) = DEMAND(r)
! Bounds on flows
forall(p in PLANT, r in REGION | exists(flow(p,r)))
flow(p,r) <= TRANSCAP(p,r)
insightminimize(MinCost) ! Solve problem through Xpress Insight
setparam("datetimefmt", "%0d-%N-%y, %0H:%0M:%0S")
RunDate:= string(datetime(SYS_NOW))
if getprobstat=XPRS_OPT then
writeln("Solution: ", getobjval)
! Result objects accessed by Optimization Modeler
MincostSol:= getobjval
pltotal:= array(p in PLANT) sum(r in REGION) flow(p,r).sol
rgtotal:= array(r in REGION) sum(p in PLANT) flow(p,r).sol
else
writeln("No solution found")
end-if
end-model
|
<vdl version="4.6">
<!-- Implementation of a table row filter -->
<script>
function filterRow(rowData, idx, current, Select) {
// Plant === CURRENTPLANT && SELCUST for selecting the customers
return (rowData[0] === current.value) && Select(rowData[1]).value;
}
</script>
<vdl-page>
<!-- VDL header and 'page' must always be present -->
<!-- Structural element 'section': print header text for a section -->
<vdl-section heading="Customer selection">
<vdl-row>
<vdl-column size="12">
<vdl-row>
<vdl-column><span vdl-text="Example of interaction between VDL elements: selecting customers and plant locations for display of input and result data in a filtered table."></span></vdl-column>
</vdl-row>
<vdl-row>
<!-- Display the input values as a table for indices selected
upfront. -->
<vdl-column size="4" heading="Customer selection">
<vdl-table>
<vdl-table-column entity="SELCUST" editable="true"></vdl-table-column>
</vdl-table>
</vdl-column>
<vdl-column size="8" heading="Data and results for selected customers">
<vdl-form>
<vdl-field label="Plants" entity="CURRENTPLANT" options-set="PLANT"></vdl-field>
</vdl-form>
<vdl-table row-filter="=function(rowData, idx) {return filterRow(rowData, idx, scenario.entities.CURRENTPLANT, scenario.entities.SELCUST)}">
<vdl-table-column entity="TRANSCAP"></vdl-table-column>
<vdl-table-column entity="DISTANCE"></vdl-table-column>
<vdl-table-column entity="flow"></vdl-table-column>
</vdl-table>
</vdl-column>
</vdl-row>
</vdl-column>
</vdl-row>
</vdl-section>
</vdl-page>
</vdl>
|
(!******************************************************
Mosel User Guide Example Problems
=================================
file transport_graph.mos
````````````````````````
Graphical solution output with mmsvg.
(c) 2008 Fair Isaac Corporation
author: S.Heipcke, 2006, rev. Sep. 2017
*******************************************************!)
model "Transport (Graph)"
uses "mmxprs", "mmsvg"
forward procedure draw_solution
declarations
REGION: set of string ! Set of customer regions
PLANT: set of string ! Set of plants
DEMAND: array(REGION) of real ! Demand at regions
PLANTCAP: array(PLANT) of real ! Production capacity at plants
PLANTCOST: array(PLANT) of real ! Unit production cost at plants
TRANSCAP: dynamic array(PLANT,REGION) of real
! Capacity on each route plant->region
DISTANCE: dynamic array(PLANT,REGION) of real
! Distance of each route plant->region
FUELCOST: real ! Fuel cost per unit distance
flow: dynamic array(PLANT,REGION) of mpvar ! Flow on each route
end-declarations
initializations from 'transprt.dat'
DEMAND
[PLANTCAP,PLANTCOST] as 'PLANTDATA'
[DISTANCE,TRANSCAP] as 'ROUTES'
FUELCOST
end-initializations
! Create the flow variables that exist
forall(p in PLANT, r in REGION | exists(TRANSCAP(p,r)) ) create(flow(p,r))
! Objective: minimize total cost
MinCost:= sum(p in PLANT, r in REGION | exists(flow(p,r)))
(FUELCOST * DISTANCE(p,r) + PLANTCOST(p)) * flow(p,r)
! Limits on plant capacity
forall(p in PLANT) sum(r in REGION) flow(p,r) <= PLANTCAP(p)
! Satisfy all demands
forall(r in REGION) sum(p in PLANT) flow(p,r) = DEMAND(r)
! Bounds on flows
forall(p in PLANT, r in REGION | exists(flow(p,r)))
flow(p,r) <= TRANSCAP(p,r)
minimize(MinCost) ! Solve the problem
draw_solution ! Solution drawing (SVG)
!***********************************************************************
procedure draw_solution
declarations
YP: array(PLANT) of integer ! y-coordinates of plants
YR: array(REGION) of integer ! y-coordinates of sales regions
end-declarations
! Scale the size of the displayed graph
svgsetgraphviewbox(0.25,0.75,3.75,getsize(REGION)+1)
svgsetgraphscale(100)
! Determine y-coordinates for plants and regions
ct:= 1+floor((getsize(REGION)-getsize(PLANT))/2)
forall(p in PLANT, ct as counter) YP(p):= ct
ct:=1
forall(r in REGION, ct as counter) YR(r):= ct
! Draw the plants
svgaddgroup("PGr", "Plants", svgcolor(0,63,95))
forall(p in PLANT) svgaddtext(0.55, YP(p)-0.1, p)
! Draw the sales regions
svgaddgroup("RGr", "Regions", svgcolor(0,157,169))
forall(r in REGION) svgaddtext(3.1, YR(r)-0.1, r)
! Draw all transport routes
svgaddgroup("TGr", "Routes", SVG_GREY)
forall(p in PLANT, r in REGION | exists(TRANSCAP(p,r)) )
svgaddline(1, YP(p), 3, YR(r))
! Draw the routes used by the solution
svgaddgroup("SGr", "Solution", SVG_ORANGE)
forall(p in PLANT, r in REGION | exists(flow(p,r)) and getsol(flow(p,r)) > 0)
svgaddarrow(1, YP(p), 3, YR(r))
! Save graphic in SVG format
svgsave("transport.svg")
! Display the graphic
svgrefresh
svgwaitclose("Close browser window to terminate model execution.", 1)
end-procedure
end-model
|