/* -*- Mode: Text -*-* */ /********************************************************************\ * File: grid.hs * * Date: 11/28/1997 * * Author: Cem Unsal * * Robotics Institute, Carnegie-Mellon University * * unsal@ri.cmu.edu * * * * Description: * * The Cell Creator, which also includes the position of the cells * * is used to describe the grid to be used in the simulation. * * See documentation for details. * * * * Cell generation is not automated; the locations and the adjoint * * cell definitions must be defined carefully. * * * * External C functions: * * * * This file is distributed under the conditions described in the * * file 'CONDITIONS' which should accompany this file. * \********************************************************************/ #ifndef SAHS_GRID_HS #define SAHS_GRID_HS #include /* These numbers must be compatible with highway description. * See associated highway description file. */ global number xmax := 600; global number ymax := 600; global number xmin := 0; global number ymin := 0; global set(Cell) Cells; global CellCreator ccc := create(CellCreator); type CellCreator { output Cell newcell; state number m, n; // Cell matrix size number c := 150; // Cell size (could be automated) continuous number i, j; // indices for cell creation setup do { m := ceil(xmax/c); n := ceil(ymax/c); i := 0; j := 0; }; discrete cc, neig, done; export finished; transition cc -> cc {} when i < m define { Cell nn := create(Cell, x := i * c, y := j * c, cs := c); } do { newcell := nn; Cells := Cells + {nn}; i := i + 1; }, cc -> cc {} when i = m and j < n-1 do { i := 0; j := j + 1; }, cc -> neig {} when i = m and j = n-1 do { i := 0; j := 0; }, neig -> neig {} when i < m define { /* This is a sad way of defining the neighbors, but it works */ set(Cell) curset := {cc : cc in Cells | x(cc) = i*c and y(cc)=j*c}; Cell cur := minel f in curset : x(f)-i*c; set(Cell) right := { a : a in Cells | x(a) = x(cur) + c }; set(Cell) left := {b : b in Cells | x(b) = x(cur) - c }; set(Cell) down := {d : d in Cells | y(d) = y(cur) + c}; set(Cell) up := {e : e in Cells | y(e) = y(cur) - c}; set(Cell) upright := up * right; set(Cell) upleft := up * left; set(Cell) downright := down * right; set(Cell) downleft := down * left; Cell ce := if size(right) = 0 then nil else minel a in right : abs(y(a)-y(cur)); Cell cw := if size(left) = 0 then nil else minel a in left : abs(y(a)-y(cur)); Cell cn := if size(up) = 0 then nil else minel a in up : abs(x(a)-x(cur)); Cell cs := if size(down) = 0 then nil else minel a in down : abs(x(a)-x(cur)); Cell cse := if size(downright) = 0 then nil else minel a in downright : 1; Cell csw := if size(downleft) = 0 then nil else minel a in downleft : 1; Cell cne := if size(upright) = 0 then nil else minel a in upright : 1; Cell cnw := if size(upleft) = 0 then nil else minel a in upleft : 1; set(Cell) sce := if ce = nil then {} else {ce}; set(Cell) scw := if cw = nil then {} else {cw}; set(Cell) scs := if cs = nil then {} else {cs}; set(Cell) scn := if cn = nil then {} else {cn}; set(Cell) scse := if cse = nil then {} else {cse}; set(Cell) scsw := if csw = nil then {} else {csw}; set(Cell) scne := if cne = nil then {} else {cne}; set(Cell) scnw := if cnw = nil then {} else {cnw}; } do { newcell := cur; NC(newcell) := sce + scw + scn + scs + scse + scne + scsw + scnw; i := i + 1; }, neig -> neig {} when i = m and j < n-1 do { i := 0; j := j + 1; }, neig -> done {finished} when i = m and j = n-1 ; } #endif // SAHS_GRID_HS