Example
In its present version, Mosel does not allow the user to define data structures with entries of different types. In certain cases it may nevertheless be useful to organize data in such a way. Taking the example of scheduling problems, a typical group of inhomogeneous data are those related to a task. In our example, we shall define a structure task that holds the following pieces of information:
- task name (a string)
- duration (real value)
- a special flag (Boolean)
- due date (integer value)
The following model may give an overview on the types of operations and specific access functions that we have to define in order to be able to work satisfactorily with this new type:
model "test task module"
uses "task"
declarations
R:set of integer
t:array(R) of task
s:task
end-declarations
! Assigning a task
s:=task("zero",1.5,true,3)
! Initializing a task array from file
initializations from "testtask.dat"
t
end-initializations
! Reassigning the same task
t(1):=task("one",1,true,3)
t(1):=task("two",1,true,3)
! Various ways of creating tasks
t(3):=task("three",10)
t(7):=task(7)
t(6):=task("six")
t(9):=task(3,false,9)
! Writing a task array to file
initializations to "testtask.dat"
t as 't2'
end-initializations
! Printout
writeln("s:", s)
writeln("t:", t)
! Accessing (and changing) detailed task information
forall(i in R)
writeln(i," Task ",strfmt(t(i).name,-5),": duration:", t(i).duration,
", flag:", t(i).aflag, ", due date:", t(i).duedate )
t(7).name:="seven"
t(6).duration:=4.3
t(9).aflag:=true
t(7).duedate:=10
! Comparing tasks
if t(1)<>s then
writeln("Tasks are different.")
end-if
t(0):=task("zero",1,true,3)
if t(0)=s then
writeln("Tasks are the same.")
end-if
end-model
