<?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>// Place global declarations here.


const int recov_time[400] = {0, 0, 568, 332, 236, 183, 149, 126, 109, 97, 86, 78, 71, 66, 61, 57, 53, 50, 47, 44, 42, 40, 38, 36, 35, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 24, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18, 18, 17, 17, 17, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};

//arrays defining the load
const int load_time[80] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000, 5100, 5200, 5300, 5400, 5500, 5600, 5700, 5800, 5900, 6000, 6100, 6200, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000, 7100, 7200, 7300, 7400, 7500, 7600, 7700, 7800, 7900, 8000};
const int cur[80] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const int cur_times[80] = {2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4};


const int bat_num =2;
const int id_bat[bat_num] = {0,1};

int m_delta[bat_num] ={0,0};
int n_gamma[bat_num] = {550,550};
bool bat_empty[bat_num] = {false,false};  


int j;
clock t;


const int c=166;

int meter = 0;

chan go_on;
chan a[bat_num];
chan   go_off, emptied, new_job;
broadcast chan all_empty;


//chan priority default  &lt; a;</declaration><template><name x="5" y="5">recovery</name><parameter>const int id</parameter><declaration>// Place local declarations here.
clock c_recov;</declaration><location id="id0" x="96" y="-216"><committed/></location><location id="id1" x="-152" y="-248"><name x="-192" y="-256">off</name></location><location id="id2" x="-336" y="-672"><name x="-360" y="-704">m_delta_0</name></location><location id="id3" x="-160" y="-672"><committed/></location><location id="id4" x="-336" y="-456"><name x="-368" y="-440">m_delta_1</name></location><location id="id5" x="88" y="-448"><name x="104" y="-448">m_delta_gt_1</name><label kind="invariant" x="104" y="-464">c_recov&lt;=recov_time[m_delta[id]]</label></location><init ref="id2"/><transition><source ref="id0"/><target ref="id5"/><label kind="guard" x="-120" y="-264">c_recov&gt;=recov_time[m_delta[id]]</label><label kind="assignment" x="-16" y="-296">m_delta[id]-=1,
c_recov=0</label><nail x="40" y="-326"/></transition><transition><source ref="id0"/><target ref="id5"/><label kind="guard" x="152" y="-328">c_recov&lt;recov_time[m_delta[id]]</label><nail x="144" y="-328"/></transition><transition><source ref="id5"/><target ref="id0"/><label kind="synchronisation" x="96" y="-336">a[id]?</label></transition><transition><source ref="id5"/><target ref="id1"/><label kind="synchronisation" x="-128" y="-344">all_empty?</label></transition><transition><source ref="id4"/><target ref="id1"/><label kind="synchronisation" x="-288" y="-328">all_empty?</label></transition><transition><source ref="id2"/><target ref="id3"/><label kind="synchronisation" x="-264" y="-696">a[id]?</label></transition><transition><source ref="id3"/><target ref="id5"/><label kind="guard" x="-64" y="-624">m_delta[id]&gt;1</label><label kind="assignment" x="-64" y="-608">c_recov=0</label></transition><transition><source ref="id3"/><target ref="id4"/><label kind="guard" x="-320" y="-624">m_delta[id]==1</label></transition><transition><source ref="id5"/><target ref="id5"/><label kind="guard" x="8" y="-584">m_delta[id]&gt;2 &amp;&amp;  c_recov&gt;=recov_time[m_delta[id]]</label><label kind="assignment" x="56" y="-568">m_delta[id]-=1,
c_recov=0</label><nail x="56" y="-536"/><nail x="136" y="-536"/></transition><transition><source ref="id5"/><target ref="id4"/><label kind="guard" x="-312" y="-408">m_delta[id]==2 &amp;&amp; c_recov&gt;=recov_time[m_delta[id]]</label><label kind="assignment" x="-192" y="-392">m_delta[id]-=1</label><nail x="-152" y="-408"/></transition><transition><source ref="id4"/><target ref="id5"/><label kind="synchronisation" x="-184" y="-544">a[id]?</label><label kind="assignment" x="-184" y="-528">c_recov=0</label><nail x="-152" y="-504"/></transition></template><template><name>discharge</name><parameter>const int id</parameter><declaration>
clock c_disch;</declaration><location id="id6" x="-296" y="-136"><name x="-360" y="-144">empty</name></location><location id="id7" x="-296" y="-200"><committed/></location><location id="id8" x="-296" y="-352"><name x="-272" y="-368">on</name><label kind="invariant" x="-272" y="-352">c_disch&lt;=cur_times[j]</label></location><location id="id9" x="-472" y="-352"><name x="-482" y="-382">idle</name></location><init ref="id9"/><transition><source ref="id7"/><target ref="id6"/><label kind="synchronisation" x="-288" y="-184">new_job!</label></transition><transition><source ref="id8"/><target ref="id8"/><label kind="guard" x="-480" y="-512">c_disch&gt;=cur_times[j]&amp;&amp;(1000-c)*m_delta[id]&lt;c*n_gamma[id]</label><label kind="synchronisation" x="-328" y="-496">a[id]!</label><label kind="assignment" x="-328" y="-480">n_gamma[id]-=cur[j],
m_delta[id]+=cur[j],
c_disch=0</label><nail x="-320" y="-432"/><nail x="-272" y="-432"/></transition><transition><source ref="id8"/><target ref="id7"/><label kind="guard" x="-288" y="-272">(1000-c)*m_delta[id]&gt;=c*n_gamma[id]</label><label kind="synchronisation" x="-288" y="-256">emptied!</label><label kind="assignment" x="-288" y="-240">bat_empty[id] = true</label></transition><transition><source ref="id8"/><target ref="id9"/><label kind="guard" x="-504" y="-320">(1000-c)*m_delta[id]&lt;c*n_gamma[id]</label><label kind="synchronisation" x="-416" y="-304">go_off?</label><nail x="-376" y="-320"/></transition><transition><source ref="id9"/><target ref="id8"/><label kind="synchronisation" x="-432" y="-416">go_on?</label><label kind="assignment" x="-432" y="-400">c_disch=0</label><nail x="-376" y="-384"/></transition></template><template><name>load</name><declaration>clock c_load;
</declaration><location id="id10" x="-1360" y="-936"><name x="-1370" y="-966">off</name></location><location id="id11" x="-1232" y="-624"><committed/></location><location id="id12" x="-1056" y="-808"><committed/></location><location id="id13" x="-1360" y="-808"><name x="-1424" y="-832">load_on</name><label kind="invariant" x="-1472" y="-848">t&lt;=load_time[j]</label></location><location id="id14" x="-1496" y="-808"><name x="-1512" y="-792">start</name></location><init ref="id14"/><transition><source ref="id11"/><target ref="id13"/><label kind="guard" x="-1432" y="-696">cur[j]==0</label><nail x="-1360" y="-624"/></transition><transition><source ref="id13"/><target ref="id11"/><label kind="guard" x="-1312" y="-776">t&gt;=load_time[j]&amp;&amp;cur[j]==0</label><label kind="assignment" x="-1280" y="-760">j+=1</label><nail x="-1280" y="-728"/></transition><transition><source ref="id13"/><target ref="id10"/><label kind="synchronisation" x="-1440" y="-904">all_empty?</label></transition><transition><source ref="id11"/><target ref="id13"/><label kind="guard" x="-1344" y="-696">cur[j]&gt;0</label><label kind="synchronisation" x="-1344" y="-680">new_job!</label></transition><transition><source ref="id12"/><target ref="id11"/><label kind="synchronisation" x="-1160" y="-696">go_off!</label></transition><transition><source ref="id13"/><target ref="id12"/><label kind="guard" x="-1312" y="-848">t&gt;=load_time[j]&amp;&amp;cur[j]&gt;0</label><label kind="assignment" x="-1280" y="-832">j+=1</label></transition><transition><source ref="id14"/><target ref="id13"/><label kind="synchronisation" x="-1456" y="-768">new_job!</label><label kind="assignment" x="-1456" y="-800">t=0,
j=0</label></transition></template><template><name>scheduler</name><declaration>int choice = 0;


//compare checks which battery is better, when the second of the two is best 
//the returned value is true.
/*bool compare(int k, int l)
{
	bool test = false;
	
	if(bat_empty[k]&amp;&amp; ! bat_empty[l])
		test = true;
	else if(! bat_empty[k] &amp;&amp; ! bat_empty[l]){
		if(c*gamma[l]-(1000-c)*delta[l]&gt;c*gamma[k]-(1000-c)*delta[k])
			test = true;
	}

	return test;
}

int next_choice(){
	int temp_choice=0;
	int l;
	for(l=1; l&lt;bat_num;l++){
		if(compare(temp_choice,l)){
		temp_choice=l;
		}
	}
	return temp_choice;
}
*/
</declaration><location id="id15" x="-984" y="-360"><name x="-992" y="-344">off</name></location><location id="id16" x="-848" y="-496"><name x="-832" y="-504">choose</name><committed/></location><location id="id17" x="-1120" y="-496"><name x="-1168" y="-504">wait</name></location><init ref="id17"/><transition><source ref="id16"/><target ref="id15"/><label kind="synchronisation" x="-928" y="-416">all_empty?</label></transition><transition><source ref="id17"/><target ref="id15"/><label kind="synchronisation" x="-1112" y="-416">all_empty?</label></transition><transition><source ref="id16"/><target ref="id17"/><label kind="synchronisation" x="-1040" y="-608">go_on!</label><nail x="-848" y="-584"/><nail x="-1120" y="-584"/></transition><transition><source ref="id17"/><target ref="id16"/><label kind="synchronisation" x="-1032" y="-512">new_job?</label></transition></template><template><name>max</name><declaration>
clock c_meter;

int empty_count = 0;


int sum_gamma(){

int n;
int sum = 0;

for(n=0; n&lt;bat_num; n++){
	sum = sum+n_gamma[n];
	} 


return sum;
}</declaration><location id="id18" x="-544" y="-176"><name x="-600" y="-184">done</name></location><location id="id19" x="-544" y="-280"><name x="-584" y="-288">off</name><label kind="invariant" x="-528" y="-288">c_meter&lt;=meter&amp;&amp;
cost'==1</label></location><location id="id20" x="-544" y="-376"><committed/></location><location id="id21" x="-544" y="-480"><name x="-580" y="-488">on</name></location><init ref="id21"/><transition><source ref="id19"/><target ref="id18"/><label kind="guard" x="-536" y="-240">c_meter&gt;=meter</label></transition><transition><source ref="id20"/><target ref="id19"/><label kind="synchronisation" x="-528" y="-344">all_empty!</label></transition><transition><source ref="id21"/><target ref="id20"/><label kind="guard" x="-536" y="-448">empty_count==bat_num-1</label><label kind="synchronisation" x="-536" y="-464">emptied?</label><label kind="assignment" x="-536" y="-433">c_meter=0,
meter = sum_gamma()</label></transition><transition><source ref="id21"/><target ref="id21"/><label kind="guard" x="-620" y="-568">empty_count&lt;bat_num-1</label><label kind="synchronisation" x="-620" y="-584">emptied?</label><label kind="assignment" x="-620" y="-552">empty_count+=1</label><nail x="-500" y="-528"/><nail x="-588" y="-528"/></transition></template><system>// Place template instantiations here.

chan bat1, bat2;
//int delta1, delta2;




discharge0 = discharge(id_bat[0]);
recovery0 = recovery(id_bat[0]);
discharge1 = discharge(id_bat[1]);
recovery1 = recovery(id_bat[1]);

// List one or more processes to be composed into a system.
system  max,scheduler,load &lt; recovery0, recovery1 &lt; discharge0, discharge1;</system></nta>