esharp: nat = let x : natin x -- is not yet defined
state Store of
pes: inmap Site_label to Pot_explosion_site
exs: inmap Site_label to Exposed_site
xmax: Metre
ymax: Metre inv mk_Store(pes,exs,xmax,ymax) ==
xmax > 0 and ymax > 0 and dom pes subsetdom exs and forall p insetdom pes & is_Storage_building(exs(p).building.type) init store == store = mk_Store({|->},{|->},Xmax,Ymax) end
functions
rectangular: seqof Point -> bool
rectangular(v) ==
distance(v(1),v(2)) = distance(v(3),v(4)) and
distance(v(1),v(4)) = distance(v(2),v(3)) and
distance(v(1),v(3)) = distance(v(2),v(4)) and cardelems v = len v prelen v = 4;
distance: Point * Point -> Metre
distance(p1,p2) == sqrt((p2.x-p1.x)**2 + (p2.y-p1.y)**2);
sqrt (x: real) s:Realp pre x >= 0 post s >= 0 and s**2 = x;
suff_space_at:Object * Magazine * Point -> bool
suff_space_at(o,m,p) ==
0 < p.x + o.xlen and p.x + o.xlen <= m.length and
0 < p.y + o.ylen and p.y + o.ylen <= m.breadth and
0 < o.zlen and o.zlen <= m.height and forall a insetrng m.elements &
((a.x > p.x + o.xlen) or (a.x + a.object.xlen < p.x)) and
((a.y > p.y + o.ylen) or (a.y + a.object.ylen < p.y));
safe_addition: Object * Magazine * Point -> bool
safe_addition(o,m,p) ==
suff_space_at(o,m,p) and
within_hazard(o,m) and
all_compatible(o,m) and
suff_capacity(o,m);
rel_pos:Pot_explosion_site * Exposed_site -> nat
rel_pos(pes,exs) == floor(ang_sep(pes,exs)) div 90;
table_entry: Pot_explosion_site * Exposed_site -> Table_Co_ordinate
table_entry(pes,exs) == let inc = rel_pos(pes,exs) in let exs_ro = if is_Storage_building(exs.building.type) then orientation((inc + exs.door) mod 4) else <NONE>,
pes_ro = if pes.mgzn.type = <EARTHCOVEREDBUILDING> then orientation((inc + pes.door) mod 4) else <NONE> in let o_exs = mk_(exs.building.type,exs_ro),
o_pes = mk_(pes.mgzn.type,pes_ro) in
mk_(o_exs,o_pes);
min(s: set1 of Realp) m: Realp post m inset s andforall x inset s & m <= x;
max(s: set1 of Realp) m:Realp post m inset s andforall x inset s & m >= x;
side: Point * Point -> setof Point
side(p1,p2) == if p2.x = p1.x then { mk_Point(p1.x,y) | y: Realp &
truncated(y) and
min({p1.y,p2.y}) <= y and y<=max({p1.y,p2.y})} else { mk_Point(x,y) | x: Realp, y: Realp &
truncated(x) and
truncated(y) and
min({p1.x,p2.x}) <= x and x <= max({p1.x,p2.x}) and
min({p1.y,p2.y}) <= y and y <= max({p1.y,p2.y}) and if x<> p1.x then (y - p1.y)/(x - p1.x) = (p2.y - p1.y)/(p2.x - p1.x) else y = p1.y};
qd: Pot_explosion_site * Exposed_site -> Kg
qd(pes,exs) == let d = shortest_dist(pes,exs),
tbe = table_entry(pes,exs) in cases pes.mgzn.hzd :
(<ONEPONE>) -> if tbe inset exceptions_hd1_1 then (if d < 180 then 0.54 * d ** (3/2) elseif (180 <=d and d < 240) then 0.03*d ** 2 else 9.1*10**(-5) * d**3) else asharp(<ONEPONE>)(tbe) *d**3,
(<ONEPTWO>) -> if tbe inset exceptions_hd1_2 then (<INFINITY>) else asharp(<ONEPTWO>)(tbe) * d**5.5,
(<ONEPTHREE>) -> if tbe inset exceptions_hd1_3a then <INFINITY> elseif tbe inset exceptions_hd1_3b then asharp(<ONEPTHREE>)(tbe) * d**2 else asharp(<ONEPTHREE>)(tbe) * d**3,
(<ONEPFOUR>) ->
<INFINITY> end;
nearest_storage_building(pes:Pot_explosion_site,
exs: setof Exposed_site)e:Exposed_site preexists ex inset exs & is_Storage_building(ex.building.type) post e inset exs and
is_Storage_building(e.building.type) and forall ex inset exs &
is_Storage_building(ex.building.type) =>
shortest_dist(pes,e) <= shortest_dist(pes,ex);
nearest_inhabited_building(pes:Pot_explosion_site,
exs: setof Exposed_site)e:Exposed_site preexists ex inset exs & ex.building.type.kind = <INHABITEDBUILDING> post e inset exs and
e.building.type.kind = <INHABITEDBUILDING> and forall ex inset exs &
ex.building.type.kind = <INHABITEDBUILDING> =>
shortest_dist(pes,e) <= shortest_dist(pes,ex);
nearest_traffic_route(pes:Pot_explosion_site,
exs: setof Exposed_site)e:Exposed_site preexists ex inset exs & ex.building.type.kind = <TRAFFICROUTE> post e inset exs and
e.building.type.kind = <TRAFFICROUTE> and forall ex inset exs &
ex.building.type.kind = <TRAFFICROUTE> =>
shortest_dist(pes,e) <= shortest_dist(pes,ex);
nearest_process_building(pes:Pot_explosion_site,
exs: setof Exposed_site)e:Exposed_site preexists ex inset exs & is_Process_building(ex.building.type) post e inset exs and
is_Process_building(e.building.type) and
(forall ex inset exs &
is_Process_building(ex.building.type) =>
shortest_dist(pes,e) <= shortest_dist(pes,ex));
nearest_buildings(pes:Pot_explosion_site, exs: setof Exposed_site)
exset: (setof Exposed_site) post (exists e inset exs & is_Storage_building(e.building.type))
=> nearest_storage_building(pes,exs) inset exset and
(exists e inset exs & is_Process_building(e.building.type))
=> nearest_process_building(pes,exs) inset exset and
(exists e inset exs & e.building.type.kind = <INHABITEDBUILDING>)
=> nearest_inhabited_building(pes,exs) inset exset and
(exists e inset exs & e.building.type.kind = <TRAFFICROUTE>)
=> nearest_traffic_route(pes,exs) inset exset;
find_max_neq:Pot_explosion_site * set1 of Exposed_site -> Kg
find_max_neq(pes,exs) ==
min({qd(pes,e)|e inset nearest_buildings(pes,exs)});
centre(v: Quad) p: Point postforall i inset {1,...,3} &
distance(p,v(i)) = distance(p,v(1));
line_eqn: Point * Point * Point -> Line
line_eqn(p1,p2,p3) ==
mk_Line( (p1.y + p2.y - 2*p3.y)/(p1.x + p2.x - 2* p3.x),
p3.y - p3.x*((p1.y + p2.y - 2*p3.y)/(p1.x + p2.x - 2*p3.x))) pre distance(p1,p3) = distance(p2,p3);
incline:Point * Point * Point * Point * Point * Point -> real
incline(p1,p2,p3,p4,p5,p6) == let mk_Line(m1,c1) = line_eqn(p5,p6,p2) in let mk_Line(m2,c2) = line_eqn(p3,p4,p1) in let x3 = (c1-c2)/(m2-m1) in let y3 = ((m2*c1 - m1*c2)/(m2-m1)) in
sqrt( ((x3-p2.x)**2 + (y3-p2.y)**2)/((x3-p1.x)**2 + (y3-p1.y)**2)) pre distance(p1,p2) = distance(p1,p4) and
distance(p2,p5) = distance(p2,p6) and
line_eqn(p5,p6,p2).m*line_eqn(p3,p4,p1).m = -1;
ang_sep(pes:Pot_explosion_site, exs:Exposed_site) qsharp:real postlet fsharp = arctan(incline(centre(pes.vertices),centre(exs.vertices),
pes.vertices(1), pes.vertices(4), exs.vertices(1),
exs.vertices(2))) in if centre(pes.vertices).x = centre(exs.vertices).x then ( if centre(pes.vertices).y < centre(exs.vertices).y then qsharp = fsharp else qsharp = fsharp + 180) elselet m1 = line_eqn(pes.vertices(1), pes.vertices(4),
centre(pes.vertices)).m,
m2 = ((centre(exs.vertices).y - centre(pes.vertices).y)/
(centre(exs.vertices).x - centre(pes.vertices).x)) in if m2 > m1 then qsharp = fsharp else qsharp = fsharp + 180;
arctan: real -> real
arctan(r) == let res : realin res -- is not yet defined
operations
ADD_OBJECT(o:Object, elt: Element_label, site: Site_label) extwr pes: inmap Site_label to Pot_explosion_site pre site insetdom pes and exists pt: Point & (safe_addition(o,(pes(site)).mgzn,pt) and
elt notinsetdom (pes(site)).mgzn.elements) postlet p = pes~(site) in let mk_Point(x,y) = find_point(o,p.mgzn) in let new_elems = p.mgzn.elements ++ {elt |-> mk_Element(o,x,y)} in let new_mag = mu(p.mgzn, elements |-> new_elems) in let new_site = mu(p, mgzn |-> new_mag) in
pes = pes~ ++ {site |-> new_site};
REMOVE_OBJECT(elt: Element_label, site: Site_label) extwr pes: inmap Site_label to Pot_explosion_site pre site insetdom pes and elt insetdom (pes(site)).mgzn.elements postlet p = pes~(site) in let new_elems = {elt} <-: p.mgzn.elements in let new_mag = mu(p.mgzn, elements |-> new_elems) in let new_site = mu(p, mgzn |-> new_mag) in
pes = pes~ ++ {site |-> new_site};
ADD_PES(pex:Pot_explosion_site, label: Site_label,type:Storage_building) extwr pes: inmap Site_label to Pot_explosion_site wr exs: inmap Site_label to Exposed_site rd xmax, ymax: Metre preforall exp insetrng exs & minseparation(pex,exp) and forall v inseq pex.vertices &
(0 <= v.x and v.x <= xmax and
0 <= v.y and v.y <= ymax) and
label notinsetdom pes postlet new_neq = find_max_neq(pex,rng(exs~)) in let new_mgzn = mu(pex.mgzn, max_neq |-> new_neq) in let new_pex = mu (pex, mgzn |-> new_mgzn) in let new_building = mk_Building(type,pex.mgzn.length,pex.mgzn.breadth,
pex.mgzn.height) in let new_exp = mk_Exposed_site(new_building,pex.vertices,pex.door) in
pes = pes~ ++ { label |-> new_pex} and
exs = exs~ ++ { label |-> new_exp};
ADD_EXP(ex:Exposed_site, label: Site_label) extwr exs: inmap Site_label to Exposed_site rd pes: inmap Site_label to Pot_explosion_site rd xmax, ymax: Metre prenot (is_Storage_building(ex.building.type)) and forall v inseq ex.vertices &
(0<=v.x and v.x <= xmax and
0<=v.y and v.y <= ymax) and
label notinsetdom exs and forall pex insetrng pes & let proposed_neq = find_max_neq(pex, rng(exs ++ {label |-> ex})) in if proposed_neq <> <INFINITY> then find_max_neq(pex,rng(exs)) <= proposed_neq elsetrue post exs = exs~ ++ {label |-> ex}
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.