<?xml version="1.0" encoding="utf-8"?><!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_1.dtd'><nta><declaration>int memory = 96;

int scan_time;
int recover_time;
int no_recover_time=0;
int ip1_time;
int ip2_time;
int print_ip_time;    
int totalMB;

const int n=8; //n specify the number of concurrent pages

urgent chan start_scanner;
urgent chan start_scan_ip;
urgent chan start_ip1;
urgent chan start_ip2;
urgent chan start_print_ip;
urgent chan start_up;
urgent chan start_down;

broadcast chan end_scanner;
broadcast chan end_scan_ip;
broadcast chan end_ip1;
broadcast chan end_ip2;
broadcast chan end_print_ip;
broadcast chan end_up;
broadcast chan end_down;

chan printing_claimed[n];
chan usb_transfer_claimed[n];

urgent chan printing_finished[n];
urgent chan usb_transfer_finished[n];

clock time;


void setScannerTime()
{
    scan_time = 6;
    recover_time = 1;
}
int getIp1Time()
{
    return 3;
} 

void setIp1Time()
{
    ip1_time = 3;
}    
    

void setIp2Time()
{
    ip2_time = 3;
}

void setPrintTime()
{
    print_ip_time = 4;
    
}





</declaration><template><name x="5" y="5">RESOURCE</name><parameter>urgent chan &amp;start_resource,broadcast chan &amp;end_resource, int &amp;execution_time, int &amp;recover_time</parameter><declaration>clock x;
</declaration><location id="id0" x="0" y="0"><name x="-32" y="16">RECOVERING</name><label kind="invariant" x="-32" y="40">x &lt;= recover_time</label></location><location id="id1" x="96" y="-96"><name x="64" y="-128">RUNNING</name><label kind="invariant" x="120" y="-112">x &lt;= execution_time</label></location><location id="id2" x="-96" y="-96"><name x="-112" y="-128">IDLE</name></location><init ref="id2"/><transition><source ref="id0"/><target ref="id2"/><label kind="guard" x="-184" y="-48">x &gt;= recover_time</label><label kind="synchronisation" x="-168" y="-64">end_resource!</label></transition><transition><source ref="id1"/><target ref="id0"/><label kind="guard" x="72" y="-64">x &gt;= execution_time</label><label kind="assignment" x="72" y="-48">x := 0</label></transition><transition><source ref="id2"/><target ref="id1"/><label kind="synchronisation" x="-48" y="-120">start_resource?</label><label kind="assignment" x="-48" y="-136">x := 0</label></transition></template><template><name>USB_BUS</name><declaration>clock x_up, x_down;
//int MB_up=12, MB_down=12;

int MB_up, MB_down;
const int high_speed=3;

//divide function for rounding up in case of not null remainder
int divide(int a, int b) 
{
   if ((a % b) == 0)
	{return a/b; }
	{return (a/b) + 1;}
}


</declaration><location id="id3" x="-14720" y="-800"><name x="-14704" y="-832">DOWN</name><label kind="invariant" x="-14704" y="-816">x_down&lt;=divide(MB_down,high_speed)</label></location><location id="id4" x="-14720" y="-528"><name x="-14760" y="-512">UP_AND_DOWN</name><label kind="invariant" x="-14760" y="-496">x_up&lt;=divide(MB_up,high_speed) &amp;&amp; 
x_down&lt;=divide(MB_down,high_speed)</label></location><location id="id5" x="-15272" y="-528"><name x="-15280" y="-512">UP</name><label kind="invariant" x="-15384" y="-488">x_up&lt;=divide(MB_up,high_speed)</label></location><location id="id6" x="-15272" y="-800"><name x="-15312" y="-832">INIT</name></location><init ref="id6"/><transition><source ref="id4"/><target ref="id5"/><label kind="guard" x="-15168" y="-584">x_down&gt;=divide(MB_down,high_speed)</label><label kind="synchronisation" x="-15168" y="-568">end_down!</label><label kind="assignment" x="-15168" y="-552">MB_down :=0</label></transition><transition><source ref="id4"/><target ref="id3"/><label kind="guard" x="-14888" y="-720">x_up&gt;=divide(MB_up,high_speed)</label><label kind="synchronisation" x="-14888" y="-704">end_up!</label><label kind="assignment" x="-14888" y="-688">MB_up := 0</label></transition><transition><source ref="id3"/><target ref="id6"/><label kind="guard" x="-15112" y="-872">x_down&gt;=divide(MB_down,high_speed)</label><label kind="synchronisation" x="-15112" y="-888">end_down!</label><label kind="assignment" x="-15112" y="-856">MB_down :=0</label><nail x="-15064" y="-824"/></transition><transition><source ref="id5"/><target ref="id6"/><label kind="guard" x="-15536" y="-704">x_up&gt;=divide(MB_up,high_speed)</label><label kind="synchronisation" x="-15360" y="-688">end_up!</label><label kind="assignment" x="-15384" y="-672">MB_up :=0</label><nail x="-15304" y="-648"/></transition><transition><source ref="id3"/><target ref="id4"/><label kind="synchronisation" x="-14608" y="-632">start_up?</label><label kind="assignment" x="-14608" y="-616">MB_up=totalMB,
x_up:=0</label><nail x="-14616" y="-608"/></transition><transition><source ref="id6"/><target ref="id3"/><label kind="synchronisation" x="-15216" y="-800">start_down?</label><label kind="assignment" x="-15216" y="-784">MB_down=totalMB,
x_down :=0</label></transition><transition><source ref="id5"/><target ref="id4"/><label kind="synchronisation" x="-15104" y="-456">start_down?</label><label kind="assignment" x="-15104" y="-440">MB_down :=totalMB,
x_down :=0</label><nail x="-15072" y="-464"/></transition><transition><source ref="id6"/><target ref="id5"/><label kind="synchronisation" x="-15264" y="-720">start_up?</label><label kind="assignment" x="-15264" y="-704">MB_up := totalMB,
x_up:=0</label></transition></template><template><name>AGENT_AUTOMATON</name><parameter>chan &amp;resource_claimed,urgent chan &amp;resource_released, urgent chan &amp;start_resource, broadcast chan &amp;end_resource</parameter><location id="id7" x="-520" y="-136"></location><location id="id8" x="-264" y="-136"></location><location id="id9" x="-264" y="-256"></location><location id="id10" x="-520" y="-256"></location><init ref="id10"/><transition><source ref="id7"/><target ref="id10"/><label kind="synchronisation" x="-512" y="-216">resource_released!</label></transition><transition><source ref="id8"/><target ref="id7"/><label kind="synchronisation" x="-432" y="-160">end_resource?</label></transition><transition><source ref="id9"/><target ref="id8"/><label kind="synchronisation" x="-368" y="-184">start_resource!</label></transition><transition><source ref="id10"/><target ref="id9"/><label kind="synchronisation" x="-472" y="-256">resource_claimed?</label></transition></template><template><name>USE_CASE_DIRECT_COPY</name><parameter>int i, int dataToBeTransfered, int memory_ip2, int memory_usb,int arrivalTime</parameter><declaration>clock x;</declaration><location id="id11" x="-496" y="-760"></location><location id="id12" x="-496" y="-1048"><label kind="invariant" x="-480" y="-1056">x &lt;= arrivalTime</label></location><location id="id13" x="-104" y="-760"></location><location id="id14" x="-104" y="-864"></location><location id="id15" x="-104" y="-712"><name x="-88" y="-712">DONE</name></location><location id="id16" x="-104" y="-808"></location><location id="id17" x="-104" y="-936"><label kind="comments">In the requirements it is written that: "IP2 has higher throughput than both print ip and usb client". Sometimes these can finish in the same time. The subtree from beneath is supposed to solve any kind of situations between these shared resources.

The case when printer finishes before ip2 and usb, is solved by the separate automaton:UCE_CASE_PRINT</label><committed/></location><location id="id18" x="-104" y="-1000"><committed/></location><location id="id19" x="-104" y="-1064"></location><location id="id20" x="-496" y="-704"></location><location id="id21" x="-496" y="-816"><label kind="invariant" x="-480" y="-824">x &lt;= scan_time-getIp1Time()</label></location><location id="id22" x="-496" y="-864"><committed/></location><location id="id23" x="-496" y="-976"></location><init ref="id12"/><transition><source ref="id21"/><target ref="id11"/><label kind="guard" x="-488" y="-800">x &gt;= scan_time - getIp1Time()</label></transition><transition><source ref="id12"/><target ref="id23"/><label kind="guard" x="-488" y="-1032">x&gt;=arrivalTime</label></transition><transition><source ref="id13"/><target ref="id15"/><label kind="synchronisation" x="-96" y="-752">usb_transfer_finished[i]?</label><label kind="assignment" x="-96" y="-736">memory:=memory+memory_usb</label></transition><transition><source ref="id16"/><target ref="id13"/><label kind="synchronisation" x="-96" y="-800">printing_finished[i]?</label></transition><transition><source ref="id14"/><target ref="id16"/><label kind="synchronisation" x="-96" y="-856">end_ip2?</label><label kind="assignment" x="-96" y="-840">memory:=memory+memory_ip2</label><label kind="comments">We assume that IP2 always finishes before printer or usb_bus.</label></transition><transition><source ref="id17"/><target ref="id14"/><label kind="synchronisation" x="-96" y="-928">usb_transfer_claimed[i]!</label><label kind="assignment" x="-96" y="-912">totalMB=dataToBeTransfered</label></transition><transition><source ref="id18"/><target ref="id17"/><label kind="synchronisation" x="-96" y="-992">printing_claimed[i]!</label><label kind="assignment" x="-96" y="-976">setPrintTime()</label></transition><transition><source ref="id19"/><target ref="id18"/><label kind="synchronisation" x="-96" y="-1048">start_ip2!</label><label kind="assignment" x="-96" y="-1032">setIp2Time()</label></transition><transition><source ref="id23"/><target ref="id22"/><label kind="guard" x="-488" y="-968">memory&gt;=memory_ip2+memory_usb</label><label kind="synchronisation" x="-488" y="-952">start_scanner!</label><label kind="assignment" x="-488" y="-936">x:=0,
setScannerTime(),
memory=memory-memory_ip2-memory_usb</label></transition><transition><source ref="id20"/><target ref="id19"/><label kind="synchronisation" x="-376" y="-704">end_ip1?</label><nail x="-160" y="-704"/><nail x="-160" y="-1064"/></transition><transition><source ref="id11"/><target ref="id20"/><label kind="synchronisation" x="-488" y="-752">start_ip1!</label><label kind="assignment" x="-488" y="-736">setIp1Time()</label></transition><transition><source ref="id22"/><target ref="id21"/><label kind="synchronisation" x="-488" y="-856">start_scan_ip!</label></transition></template><template><name>USE_CASE_SIMPLE_PRINT</name><parameter>int dataToBeTransfered,int memory_printer, int  arrivalTime</parameter><declaration>clock x;</declaration><location id="id24" x="-488" y="-600"><label kind="invariant" x="-464" y="-608">x &lt;= arrivalTime</label></location><location id="id25" x="-488" y="-192"><name x="-472" y="-200">DONE</name></location><location id="id26" x="-488" y="-272"></location><location id="id27" x="-488" y="-416"></location><location id="id28" x="-488" y="-344"></location><location id="id29" x="-488" y="-528"></location><init ref="id24"/><transition><source ref="id24"/><target ref="id29"/><label kind="guard" x="-472" y="-584">x&gt;=arrivalTime</label></transition><transition><source ref="id26"/><target ref="id25"/><label kind="synchronisation" x="-480" y="-248">end_print_ip?</label><label kind="assignment" x="-480" y="-232">memory:=memory+memory_printer</label></transition><transition><source ref="id27"/><target ref="id28"/><label kind="synchronisation" x="-480" y="-400">end_down?</label></transition><transition><source ref="id28"/><target ref="id26"/><label kind="synchronisation" x="-480" y="-328">start_print_ip!</label><label kind="assignment" x="-480" y="-312">setPrintTime()</label></transition><transition><source ref="id29"/><target ref="id27"/><label kind="guard" x="-480" y="-512">memory&gt;=memory_printer</label><label kind="synchronisation" x="-480" y="-496">start_down!</label><label kind="assignment" x="-480" y="-480">totalMB=dataToBeTransfered,
memory:=memory-memory_printer</label></transition></template><template><name>USE_CASE_SCAN_TO_EMAIL</name><parameter>int i, int dataToBeTransfered, int memory_ip2, int memory_usb, int arrivalTime</parameter><declaration>clock x;</declaration><location id="id30" x="-224" y="-488"></location><location id="id31" x="-224" y="-792"><label kind="invariant" x="-208" y="-800">x &lt;= arrivalTime</label></location><location id="id32" x="-224" y="-184"></location><location id="id33" x="-224" y="-32"><name x="-208" y="-40">DONE</name></location><location id="id34" x="-224" y="-112"></location><location id="id35" x="-224" y="-280"><committed/></location><location id="id36" x="-224" y="-376"></location><location id="id37" x="-224" y="-440"></location><location id="id38" x="-224" y="-536"><label kind="invariant" x="-208" y="-544">x &lt;= scan_time - getIp1Time()</label></location><location id="id39" x="-224" y="-600"><committed/></location><location id="id40" x="-224" y="-728"></location><init ref="id31"/><transition><source ref="id38"/><target ref="id30"/><label kind="guard" x="-216" y="-520">x &gt;= scan_time - getIp1Time()</label></transition><transition><source ref="id31"/><target ref="id40"/><label kind="guard" x="-216" y="-776">x&gt;= arrivalTime</label></transition><transition><source ref="id34"/><target ref="id33"/><label kind="synchronisation" x="-216" y="-96">usb_transfer_finished[i]?</label><label kind="assignment" x="-216" y="-80">memory:=memory+memory_usb</label></transition><transition><source ref="id32"/><target ref="id34"/><label kind="synchronisation" x="-216" y="-168">end_ip2?</label><label kind="assignment" x="-216" y="-152">memory:=memory+memory_ip2</label><label kind="comments">We assume that IP2 always finishes before printer or usb_bus.</label></transition><transition><source ref="id35"/><target ref="id32"/><label kind="synchronisation" x="-216" y="-264">usb_transfer_claimed[i]!</label><label kind="assignment" x="-216" y="-248">totalMB=dataToBeTransfered</label></transition><transition><source ref="id36"/><target ref="id35"/><label kind="synchronisation" x="-216" y="-344">start_ip2!</label><label kind="assignment" x="-216" y="-328">setIp2Time()</label></transition><transition><source ref="id40"/><target ref="id39"/><label kind="guard" x="-216" y="-712">memory&gt;=memory_ip2+memory_usb</label><label kind="synchronisation" x="-216" y="-696">start_scanner!</label><label kind="assignment" x="-216" y="-680">x:=0,
setScannerTime(),
memory:=memory-memory_ip2-memory_usb</label></transition><transition><source ref="id37"/><target ref="id36"/><label kind="synchronisation" x="-216" y="-424">end_ip1?</label></transition><transition><source ref="id30"/><target ref="id37"/><label kind="synchronisation" x="-216" y="-480">start_ip1!</label><label kind="assignment" x="-216" y="-464">setIp1Time()</label></transition><transition><source ref="id39"/><target ref="id38"/><label kind="synchronisation" x="-216" y="-592">start_scan_ip!</label></transition></template><template><name>USE_CASE_SCAN_TO_STORE</name><parameter>int dataToBeTransfered, int memory_usb, int arrivalTime</parameter><declaration>clock x;</declaration><location id="id41" x="-224" y="-488"></location><location id="id42" x="-224" y="-800"><label kind="invariant" x="-208" y="-808">x &lt;= arrivalTime</label></location><location id="id43" x="-224" y="-352"></location><location id="id44" x="-224" y="-192"><name x="-208" y="-200">DONE</name></location><location id="id45" x="-224" y="-280"></location><location id="id46" x="-224" y="-440"></location><location id="id47" x="-224" y="-536"><label kind="invariant" x="-208" y="-544">x &lt;= scan_time - getIp1Time()</label></location><location id="id48" x="-224" y="-600"><committed/></location><location id="id49" x="-224" y="-728"></location><init ref="id42"/><transition><source ref="id47"/><target ref="id41"/><label kind="guard" x="-216" y="-520">x &gt;= scan_time - getIp1Time()</label></transition><transition><source ref="id42"/><target ref="id49"/><label kind="guard" x="-216" y="-776">x&gt;=arrivalTime</label></transition><transition><source ref="id45"/><target ref="id44"/><label kind="synchronisation" x="-216" y="-256">end_up?</label><label kind="assignment" x="-216" y="-240">memory:=memory+memory_usb</label></transition><transition><source ref="id46"/><target ref="id43"/><label kind="synchronisation" x="-216" y="-424">end_ip1?</label><label kind="comments">We assume that IP2 always finishes before printer or usb_bus.</label></transition><transition><source ref="id43"/><target ref="id45"/><label kind="synchronisation" x="-208" y="-344">start_up!</label><label kind="assignment" x="-208" y="-328">totalMB=dataToBeTransfered</label></transition><transition><source ref="id49"/><target ref="id48"/><label kind="guard" x="-216" y="-720">memory&gt;=memory_usb</label><label kind="synchronisation" x="-216" y="-704">start_scanner!</label><label kind="assignment" x="-216" y="-688">x:=0,
setScannerTime(),
memory:=memory-memory_usb</label></transition><transition><source ref="id41"/><target ref="id46"/><label kind="synchronisation" x="-216" y="-480">start_ip1!</label><label kind="assignment" x="-216" y="-464">setIp1Time()</label></transition><transition><source ref="id48"/><target ref="id47"/><label kind="synchronisation" x="-216" y="-592">start_scan_ip!</label></transition></template><template><name>USE_CASE_PRINT_FROM_CONTROLLER</name><parameter>int i, int dataToBeTransfered, int memory_printer,int arrivalTime</parameter><declaration>clock x;</declaration><location id="id50" x="-488" y="-624"><label kind="invariant" x="-464" y="-632">x &lt;= arrivalTime</label></location><location id="id51" x="-488" y="-136"></location><location id="id52" x="-488" y="-344"></location><location id="id53" x="-488" y="-72"><name x="-472" y="-80">DONE</name></location><location id="id54" x="-488" y="-200"></location><location id="id55" x="-488" y="-264"><committed/></location><location id="id56" x="-488" y="-408"></location><location id="id57" x="-488" y="-536"></location><init ref="id50"/><transition><source ref="id50"/><target ref="id57"/><label kind="guard" x="-480" y="-592">x &gt;= arrivalTime</label></transition><transition><source ref="id51"/><target ref="id53"/><label kind="synchronisation" x="-480" y="-120">printing_finished[i]?</label><label kind="assignment" x="-480" y="-104">memory:=memory+memory_printer</label></transition><transition><source ref="id56"/><target ref="id52"/><label kind="synchronisation" x="-480" y="-392">end_down?</label></transition><transition><source ref="id54"/><target ref="id51"/><label kind="synchronisation" x="-480" y="-184">end_ip2?</label></transition><transition><source ref="id55"/><target ref="id54"/><label kind="synchronisation" x="-480" y="-256">printing_claimed[i]!</label><label kind="assignment" x="-480" y="-232">setPrintTime()</label></transition><transition><source ref="id52"/><target ref="id55"/><label kind="synchronisation" x="-480" y="-328">start_ip2!</label><label kind="assignment" x="-480" y="-312">setIp2Time()</label></transition><transition><source ref="id57"/><target ref="id56"/><label kind="guard" x="-480" y="-512">memory&gt;=memory_printer</label><label kind="synchronisation" x="-480" y="-496">start_down!</label><label kind="assignment" x="-480" y="-480">totalMB=dataToBeTransfered,
memory=memory-memory_printer</label></transition></template><template><name>USE_CASE_PROCESS_FROM_STORE</name><parameter>int i, int dataToBeTransfered, int memory_ip2, int memory_usb, int arrivalTime</parameter><declaration>clock x;</declaration><location id="id58" x="-488" y="-624"><label kind="invariant" x="-464" y="-632">x &lt;= arrivalTime</label></location><location id="id59" x="-488" y="16"></location><location id="id60" x="-488" y="-344"></location><location id="id61" x="-488" y="80"><name x="-472" y="72">DONE</name></location><location id="id62" x="-488" y="-248"></location><location id="id63" x="-488" y="-48"></location><location id="id64" x="-488" y="-112"><committed/></location><location id="id65" x="-488" y="-184"></location><location id="id66" x="-488" y="-432"></location><location id="id67" x="-488" y="-536"></location><init ref="id58"/><transition><source ref="id58"/><target ref="id67"/><label kind="guard" x="-480" y="-592">x &gt;= arrivalTime</label></transition><transition><source ref="id59"/><target ref="id61"/><label kind="synchronisation" x="-480" y="32">usb_transfer_finished[i]?</label><label kind="assignment" x="-480" y="48">memory:=memory+memory_usb</label></transition><transition><source ref="id62"/><target ref="id65"/><label kind="synchronisation" x="-480" y="-232">end_ip1?</label></transition><transition><source ref="id60"/><target ref="id62"/><label kind="synchronisation" x="-480" y="-328">start_ip1!</label><label kind="assignment" x="-480" y="-304">setIp1Time()</label></transition><transition><source ref="id66"/><target ref="id60"/><label kind="synchronisation" x="-480" y="-392">end_down?</label></transition><transition><source ref="id63"/><target ref="id59"/><label kind="synchronisation" x="-480" y="-32">end_ip2?</label><label kind="assignment" x="-480" y="-16">memory:=memory+memory_ip2</label></transition><transition><source ref="id64"/><target ref="id63"/><label kind="synchronisation" x="-480" y="-104">usb_transfer_claimed[i]!</label><label kind="assignment" x="-480" y="-88">totalMB=dataToBeTransfered</label></transition><transition><source ref="id65"/><target ref="id64"/><label kind="synchronisation" x="-480" y="-176">start_ip2!</label><label kind="assignment" x="-480" y="-160">setIp2Time()</label></transition><transition><source ref="id67"/><target ref="id66"/><label kind="guard" x="-480" y="-528">memory&gt;= memory_ip2 + memory_usb</label><label kind="synchronisation" x="-480" y="-512">start_down!</label><label kind="assignment" x="-480" y="-496">totalMB=dataToBeTransfered,
memory:=memory- memory_ip2-memory_usb</label></transition></template><system>SCANNER=RESOURCE(start_scanner, end_scanner, scan_time, recover_time);
SCAN_IP=RESOURCE(start_scan_ip, end_scan_ip, scan_time, no_recover_time);
IP1=RESOURCE(start_ip1, end_ip1, ip1_time, no_recover_time);
IP2=RESOURCE(start_ip2, end_ip2, ip2_time, no_recover_time);
PRINTER=RESOURCE(start_print_ip, end_print_ip, print_ip_time, no_recover_time);

PA5=AGENT_AUTOMATON(printing_claimed[5], printing_finished[5], start_print_ip, end_print_ip);
PA6=AGENT_AUTOMATON(printing_claimed[6], printing_finished[6], start_print_ip, end_print_ip);

UBA2=AGENT_AUTOMATON(usb_transfer_claimed[2], usb_transfer_finished[2], start_up, end_up);
UBA7=AGENT_AUTOMATON(usb_transfer_claimed[7],usb_transfer_finished[7], start_up, end_up);
UBA4=AGENT_AUTOMATON(usb_transfer_claimed[4],usb_transfer_finished[4], start_up, end_up);
UBA1=AGENT_AUTOMATON(usb_transfer_claimed[1],usb_transfer_finished[1], start_up, end_up);


A2=USE_CASE_SCAN_TO_EMAIL(2, 12, 36, 12, 1);
A3=USE_CASE_SCAN_TO_STORE(12, 36, 1);
A5=USE_CASE_PRINT_FROM_CONTROLLER(5, 12, 12, 1);
A6=USE_CASE_PRINT_FROM_CONTROLLER(6, 12, 12, 0);
A7=USE_CASE_PROCESS_FROM_STORE(7, 12, 12, 12, 0);
A4=USE_CASE_PROCESS_FROM_STORE(4, 12, 12, 12, 3);
A1=USE_CASE_PROCESS_FROM_STORE(1, 12, 12, 12, 2);

system UBA1, UBA2, UBA4, UBA7, PA5, PA6, SCANNER, SCAN_IP, IP1, IP2, PRINTER, A1, A2, A3, A4, A5, A6, A7, USB_BUS;
</system></nta>