// CSG model of medium access control 
// extends model of 
// Brenguier, R.: PRALINE: A tool for computing Nash equilibria in concurrent games. 
// In: Proc. CAV’13. LNCS, vol. 8044, pp. 890–895. Springer (2013)
// with probability of failure with one or both players transmit

// concurrent stochastic game
csg 

player p1
	mac1
endplayer

player p2
	mac2
endplayer

player p3
	mac3
endplayer

const int emax; // energy bound
const int smax; // message sent bound
const double q1; // probability single user successfully sends
const double q2; // probability two users successfully send
const double q3; // probability two users successfully send

module channel

	c : bool;

	[t1,w2,w3] true -> q1 : (c'=false) + (1-q1) : (c'=true);
	[w1,t2,w3] true -> q1 : (c'=false) + (1-q1) : (c'=true);
	[w1,w2,t3] true -> q1 : (c'=false) + (1-q1) : (c'=true);

	[t1,t2,w3] true -> q2 : (c'=false) + (1-q2) : (c'=true);
	[w1,t2,t3] true -> q2 : (c'=false) + (1-q2) : (c'=true);
	[t1,w2,t3] true -> q2 : (c'=false) + (1-q2) : (c'=true);

	[t1,t2,t3] true -> q3 : (c'=false) + (1-q3) : (c'=true);

endmodule

module mac1
	
	s1 : [0..1]; // has player 1 sent?
	e1 : [0..emax] init emax; // energy level of player 1
	sent1 : [0..smax+1]; // number of messages sent by player 1
	
	[w1] true -> (s1'=0);
	[t1] e1>0 -> (s1'=c'?0:1) & (e1'=e1-1) & (sent1'=c'?sent1:(min(sent1+1,smax+1)));
	
endmodule

module mac2 = mac1 [ s1=s2, e1=e2, sent1=sent2, w1=w2, t1=t2 ] endmodule
module mac3 = mac1 [ s1=s3, e1=e3, sent1=sent3, w1=w3, t1=t3 ] endmodule