add lab3 exercises
This commit is contained in:
57
lab3/examples/bouncing.pha
Normal file
57
lab3/examples/bouncing.pha
Normal file
@@ -0,0 +1,57 @@
|
||||
// ----------------------------------------------------------
|
||||
// Hybrid System Example: Bouncing Ball
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Constants
|
||||
// ----------------------------------------------------------
|
||||
g:=1; // constant for gravity
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// System Description
|
||||
// ----------------------------------------------------------
|
||||
automaton bouncing_ball
|
||||
contr_var: v, x;
|
||||
synclabs: jump;
|
||||
loc state: while x>=0 & x<=10 & v<=10 & v>=-10 wait {x'==v & v'==-g}
|
||||
when x==0 & v<0 sync jump do {v'==-v*0.5 & x'==x} goto state;
|
||||
initially: state & x==2 & v==0;
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Define Partitioning
|
||||
// ----------------------------------------------------------
|
||||
// Add a new label for the transitions that are introduced
|
||||
// between partitions
|
||||
bouncing_ball.add_label(tau);
|
||||
|
||||
// Define the directions of the partitions
|
||||
// here: in both axes with a min. threshold of partition size 0.2
|
||||
bouncing_ball.set_refine_constraints((x, 0.2),(v,0.2),tau);
|
||||
|
||||
// With this partitioning we can use convex hull overapproximations,
|
||||
// resulting in fewer polyhedra (one per partition)
|
||||
//REACH_USE_CONVEX_HULL=true;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Define Partitioning (alternative)
|
||||
// ----------------------------------------------------------
|
||||
// We can also just partition in the v-direction, but then we must turn off
|
||||
// the convex hull (try it...)
|
||||
// bouncing_ball.set_refine_constraints((v,0.2),tau);
|
||||
// REACH_USE_CONVEX_HULL=false;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Analysis Commands
|
||||
// ----------------------------------------------------------
|
||||
reg=bouncing_ball.reachable;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Saving Data for Graphical Output
|
||||
// ----------------------------------------------------------
|
||||
reg.print("out_reach",2); // output as a list of vertices
|
||||
|
||||
// for display with graph use, e.g.:
|
||||
// graph -T X -C -B -q0.5 out_reach
|
||||
// for display with matlab use, e.g.:
|
||||
// plot_2d_vertices('out_m_reach')
|
||||
81
lab3/examples/bouncing_timed.pha
Normal file
81
lab3/examples/bouncing_timed.pha
Normal file
@@ -0,0 +1,81 @@
|
||||
// ----------------------------------------------------------
|
||||
// Hybrid System Example: Bouncing Ball
|
||||
// ----------------------------------------------------------
|
||||
// This version produces a plot of position over time.
|
||||
// A clock is added to the system to model time explicitly.
|
||||
// This gives us a another choice of partitioning: along
|
||||
// the time-axis. It's fast, but doesn't work with convex
|
||||
// hull.
|
||||
//
|
||||
// The complexity of this example requires us to put limits
|
||||
// on the bits used in polyhedral computations.
|
||||
// Otherwise, it may take very long or not terminate at all.
|
||||
REACH_CONSTRAINT_LIMIT = 48;
|
||||
REACH_CONSTRAINT_TRIGGER = 96;
|
||||
CONSTRAINT_BITSIZE = 24;
|
||||
REACH_BITSIZE_TRIGGER = 200;
|
||||
// ----------------------------------------------------------
|
||||
// Constants
|
||||
// ----------------------------------------------------------
|
||||
g:=1; // constant for gravity
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// System Description
|
||||
// ----------------------------------------------------------
|
||||
automaton bouncing_ball
|
||||
contr_var: t, x, v;
|
||||
synclabs: jump;
|
||||
loc state: while x>=0 & x<=10 & v<=10 & v>=-10 & t<=5 & t>=0 wait {x'==v & v'==-g & t'==1}
|
||||
when x==0 & v<0 sync jump do {v'==-v*0.5 & x'==x & t'==t} goto state;
|
||||
initially: state & x==2 & v==0 & t==0;
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Define Partitioning
|
||||
// ----------------------------------------------------------
|
||||
// Add a new label for the transitions that are introduced
|
||||
// between partitions
|
||||
bouncing_ball.add_label(tau);
|
||||
|
||||
// Define the directions of the partitions
|
||||
// here: in both axes with a min. threshold of partition size 0.2
|
||||
bouncing_ball.set_refine_constraints((x, 0.2),(v,0.2),tau);
|
||||
|
||||
// With this partitioning we can use convex hull overapproximations,
|
||||
// resulting in fewer polyhedra (one per partition)
|
||||
//REACH_USE_CONVEX_HULL=true;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Define Partitioning (alternative 1)
|
||||
// ----------------------------------------------------------
|
||||
// We can also just partition in the v-direction, but then
|
||||
// we must turn off convex hull (try it...)
|
||||
// bouncing_ball.set_refine_constraints((v,0.2),tau);
|
||||
// REACH_USE_CONVEX_HULL=false;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Define Partitioning (alternative 2)
|
||||
// ----------------------------------------------------------
|
||||
// We can also just partition in the t-direction, but then
|
||||
// we must turn off convex hull
|
||||
// and refine the time-elapse operator at least twice
|
||||
// at every step (try it...)
|
||||
//TIME_POST_ITER=2;
|
||||
//bouncing_ball.set_refine_constraints((t, 0.1),tau);
|
||||
//REACH_USE_CONVEX_HULL=false;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Analysis Commands
|
||||
// ----------------------------------------------------------
|
||||
reg=bouncing_ball.reachable;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Saving Data for Graphical Output
|
||||
// ----------------------------------------------------------
|
||||
reg.project_to(t, x); // remove v to get a 2-dim output
|
||||
reg.print("out_reach",2); // output as a list of vertices
|
||||
|
||||
// for display with graph use, e.g.:
|
||||
// graph -T X -C -B -q0.5 out_reach
|
||||
// for display with matlab use, e.g.:
|
||||
// plot_2d_vertices('out_m_reach')
|
||||
63
lab3/examples/evader.pha
Normal file
63
lab3/examples/evader.pha
Normal file
@@ -0,0 +1,63 @@
|
||||
// Constants definition
|
||||
//
|
||||
|
||||
// Automaton definition
|
||||
//
|
||||
automaton evader
|
||||
contr_var: e, p, x; // e position of the evader
|
||||
// p position of the pursuer
|
||||
// x timer
|
||||
synclabs: jump;
|
||||
loc ClkW:
|
||||
while 0 <= e <= 40 & 0 <= p <= 40 & x <= 2 wait
|
||||
{e'==5 & -0.5 <= p' <= 6 & x'==1}
|
||||
when (p == 0) sync jump do {e'==e & p'==40 & x'==x} goto ClkW;
|
||||
when (p == 40) sync jump do {e'==e & p'==0 & x'==x} goto ClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p > 40) sync jump do
|
||||
{e'==e & p'==p & x'==0} goto ClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p <= 40) sync jump do
|
||||
{e'==e & p'==p & x'==0} goto CntrClkW;
|
||||
when (e == 0) sync jump do {e'==e & p'==p & x'==x} goto Rescued;
|
||||
when (e == 40) sync jump do {e'==e & p'==p & x'==x} goto Rescued;
|
||||
loc CntrClkW:
|
||||
while 0 <= e <= 40 & 0 <= p <= 40 & x <= 2 wait
|
||||
{e'==-5 & -0.5 <= p' <= 6 & x'==1}
|
||||
when (p == 0) sync jump do {e'==e & p'==40 & x'==x} goto CntrClkW;
|
||||
when (p == 40) sync jump do {e'==e & p'==0 & x'==x} goto CntrClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p > 40) sync jump do
|
||||
{e'==e & p'==p & x'==0} goto ClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p <= 40) sync jump do
|
||||
{e'==e & p'==p & x'==0} goto CntrClkW;
|
||||
when (e == 0) sync jump do {e'==e & p'==p & x'==x} goto Rescued;
|
||||
when (e == 40) sync jump do {e'==e & p'==p & x'==x} goto Rescued;
|
||||
loc Rescued:
|
||||
while true wait {e'==0 & p'==0 & x'==0 };
|
||||
|
||||
initially: ClkW & x == 2 & e == 20 & p == 10;
|
||||
end
|
||||
|
||||
// Compute the reachable set
|
||||
//
|
||||
region=evader.reachable;
|
||||
//
|
||||
// Output to file
|
||||
//
|
||||
// List regions (pairs of locations names and linear formulas)
|
||||
region.print("evader_regions.txt", 0);
|
||||
// Sequence of vertices in floating point form.
|
||||
// Can be plotted with gnuplot
|
||||
// Project on e and p
|
||||
region.project_to(e, p);
|
||||
region.print("evader.txt", 2);
|
||||
|
||||
// Safety verification
|
||||
//
|
||||
// definition of bad states
|
||||
forbidden = evader.{$ & e == p};
|
||||
reach_set = evader.is_reachable(forbidden);
|
||||
reach_set.intersection_assign(forbidden);
|
||||
|
||||
echo "The intersection between the reachable set and the bad region is:";
|
||||
reach_set.is_empty;
|
||||
|
||||
|
||||
59
lab3/examples/evader2.pha
Normal file
59
lab3/examples/evader2.pha
Normal file
@@ -0,0 +1,59 @@
|
||||
// Constants definition
|
||||
//
|
||||
|
||||
// Automaton definition
|
||||
//
|
||||
automaton evader
|
||||
contr_var: e, p, x, p_zero; // e position of the evader
|
||||
// p position of the pursuer
|
||||
// x timer
|
||||
// p_zero "frozen variable" that stores the
|
||||
// initial position of the pursuer
|
||||
synclabs: jump;
|
||||
loc ClkW:
|
||||
while 0 <= e <= 40 & 0 <= p <= 40 & x <= 2 wait
|
||||
{e'==5 & -0.5 <= p' <= 6 & x'==1 & p_zero'==0}
|
||||
when (p == 0) sync jump do {e'==e & p'==40 & x'==x & p_zero'==p_zero} goto ClkW;
|
||||
when (p == 40) sync jump do {e'==e & p'==0 & x'==x & p_zero'==p_zero} goto ClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p > 40) sync jump do
|
||||
{e'==e & p'==p & x'==0 & p_zero'==p_zero} goto ClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p <= 40) sync jump do
|
||||
{e'==e & p'==p & x'==0 & p_zero'==p_zero} goto CntrClkW;
|
||||
when (e == 0) sync jump do {e'==e & p'==p & x'==x & p_zero'==p_zero} goto Rescued;
|
||||
when (e == 40) sync jump do {e'==e & p'==p & x'==x & p_zero'==p_zero} goto Rescued;
|
||||
loc CntrClkW:
|
||||
while 0 <= e <= 40 & 0 <= p <= 40 & x <= 2 wait
|
||||
{e'==-5 & -0.5 <= p' <= 6 & x'==1 & p_zero'==0}
|
||||
when (p == 0) sync jump do {e'==e & p'==40 & x'==x & p_zero'==p_zero} goto CntrClkW;
|
||||
when (p == 40) sync jump do {e'==e & p'==0 & x'==x & p_zero'==p_zero} goto CntrClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p > 40) sync jump do
|
||||
{e'==e & p'==p & x'==0 & p_zero'==p_zero} goto ClkW;
|
||||
when (x >= 2) & (0 < e < 40) & (6*e - 5*p <= 40) sync jump do
|
||||
{e'==e & p'==p & x'==0 & p_zero'==p_zero} goto CntrClkW;
|
||||
when (e == 0) sync jump do {e'==e & p'==p & x'==x & p_zero'==p_zero} goto Rescued;
|
||||
when (e == 40) sync jump do {e'==e & p'==p & x'==x & p_zero'==p_zero} goto Rescued;
|
||||
loc Rescued:
|
||||
while true wait {e'==0 & p'==0 & x'==0 & p_zero'==0};
|
||||
|
||||
initially: ClkW & x == 2 & e == 20 & p == p_zero & 0 <= p <= 40;
|
||||
end
|
||||
|
||||
// Find winning starting points for pursuer
|
||||
//
|
||||
// Compute the reachable set
|
||||
//
|
||||
region=evader.reachable;
|
||||
// Intersect with states where pursuer wins
|
||||
forbidden = evader.{$ & e == p};
|
||||
region.intersection_assign(forbidden);
|
||||
// Project on p_zero to get the initial position for the pursuer for which the
|
||||
// pursuer can win the game
|
||||
region.project_to(p_zero);
|
||||
// union over all locations
|
||||
pursuer_wins = region.loc_union;
|
||||
|
||||
echo "The pursuer can win the game if it starts from:";
|
||||
pursuer_wins.print;
|
||||
|
||||
|
||||
|
||||
16
lab3/examples/txt/evader.txt
Normal file
16
lab3/examples/txt/evader.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
20 10
|
||||
|
||||
20 10
|
||||
30 9
|
||||
30 22
|
||||
20 10
|
||||
|
||||
30 22
|
||||
30 9
|
||||
40 8
|
||||
40 34
|
||||
30 22
|
||||
|
||||
40 8
|
||||
40 34
|
||||
|
||||
4
lab3/examples/txt/evader_regions.txt
Normal file
4
lab3/examples/txt/evader_regions.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
region = evader.{
|
||||
ClkW & (x == 2 & p == 10 & e == 20 | e == 5*x + 20 & 6*e >= 5*p + 70 & e + 10*p >= 120 & e <= 30 | e == 5*x + 30 & e + 10*p >= 120 & 30 <= e <= 40 & 6*e >= 5*p + 70),
|
||||
Rescued & x == 2 & e == 40 & 8 <= p <= 34
|
||||
};
|
||||
Reference in New Issue
Block a user