[BACK]Return to dynamic_triangulations.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Root_Counts / Dynlift

Annotation of OpenXM_contrib/PHC/Ada/Root_Counts/Dynlift/dynamic_triangulations.adb, Revision 1.1.1.1

1.1       maekawa     1: with Simplices;                          use Simplices;
                      2: with Global_Dynamic_Triangulation;       use Global_Dynamic_Triangulation;
                      3: with Integer_Lifting_Utilities;          use Integer_Lifting_Utilities;
                      4: with Dynamic_Lifting_Functions;          use Dynamic_Lifting_Functions;
                      5:
                      6: package body Dynamic_Triangulations is
                      7:
                      8: -- UTILITIES :
                      9:
                     10:   procedure Initialize
                     11:                   ( l : in List; order : in boolean;
                     12:                     rest,lifted,lifted_last : in out List;
                     13:                     t : in out Triangulation ) is
                     14:
                     15:   -- DESCRIPTION :
                     16:   --   Performs initialization of the dynamic lifting algorithm.
                     17:
                     18:   -- ON ENTRY :
                     19:   --   l            the list of points to be processed;
                     20:   --   order        if true, then the order of the points will be considered;
                     21:   --   lifted       eventually points that already have been lifted;
                     22:   --   t            triangulation of the lifted points.
                     23:
                     24:   -- ON RETURN :
                     25:   --   rest         rest of point list to be processed,
                     26:   --                if empty, then the problem is degenerate;
                     27:   --   lifted       points in the initial simplex if t was empty,
                     28:   --                otherwise left unchanged;
                     29:   --   lifted_last  pointer to the last element of lifted;
                     30:   --   t            if empty on entry, then it contains an initial simplex,
                     31:   --                if the problem was not degenerate.
                     32:
                     33:     null_list : List;
                     34:     s : Simplex;
                     35:
                     36:   begin
                     37:     if Is_Null(t)
                     38:      then Initial_Simplex(l,order,s,rest);    -- start from scratch
                     39:           if (s /= Null_Simplex)
                     40:            then Construct(s,t);
                     41:                 lifted := Deep_Create(Vertices(s));
                     42:                 lifted_last := lifted;
                     43:                 while not Is_Null(Tail_Of(lifted_last)) loop
                     44:                   lifted_last := Tail_Of(lifted_last);
                     45:                 end loop;
                     46:            else rest := null_list;            -- degenerate problem
                     47:           end if;
                     48:      else rest := l;                          -- re-start
                     49:     end if;
                     50:   end Initialize;
                     51:
                     52:   procedure Next_Point ( l : in out List; order : in boolean;
                     53:                          point : out Link_to_Vector ) is
                     54:
                     55:   -- DESCRIPTION :
                     56:   --   Selects the next point out of the list l.
                     57:
                     58:   -- ON ENTRY :
                     59:   --   l          a nonempty list of points;
                     60:   --   order      if true, then the next point in the list will be choosen,
                     61:   --              otherwise, the point will be picked randomly.
                     62:
                     63:   -- ON RETURN :
                     64:   --   l          a list without the point;
                     65:   --   point      the choosen point.
                     66:
                     67:     pt : Link_to_Vector;
                     68:
                     69:   begin
                     70:     if order
                     71:      then pt := Head_Of(l);
                     72:      else pt := Max_Extreme(l,Head_Of(l)'last,-5,5);
                     73:           Swap_to_Front(l,pt);
                     74:     end if;
                     75:     l := Tail_Of(l);
                     76:     point := pt;
                     77:   end Next_Point;
                     78:
                     79: -- BASIC VERSION : WITHOUT OUTPUT GENERICS :
                     80:
                     81:   procedure Dynamic_Lifting
                     82:                 ( l : in List; order,inter : in boolean;
                     83:                   maxli : in natural; lifted,lifted_last : in out List;
                     84:                   t : in out Triangulation ) is
                     85:
                     86:     rest,inner : List;
                     87:     pt : Link_to_Vector;
                     88:     nexli : natural := 1;
                     89:
                     90:   begin
                     91:     Initialize(l,order,rest,lifted,lifted_last,t);
                     92:    -- ITERATE FOR ALL POINTS IN rest :
                     93:     while not Is_Null(rest) loop
                     94:       Next_Point(rest,order,pt);
                     95:       declare
                     96:         point : Link_to_Vector := new Vector(1..pt'last+1);
                     97:       begin
                     98:         point(1..pt'last) := pt.all;
                     99:         point(point'last) := 1; -- try to obtain an optimal lifting value !!
                    100:         if inter and then Is_In(t,point.all)
                    101:          then Clear(point); Construct(pt,inner);
                    102:          else nexli := Lift_to_Place(t,point.all);
                    103:               if (maxli > 0) and then (nexli > maxli)
                    104:                then Flatten(t);
                    105:                     nexli := 1;
                    106:               end if;
                    107:               point(point'last) := nexli;
                    108:               Update(t,point);
                    109:               Append(lifted,lifted_last,point);
                    110:         end if;
                    111:       end;
                    112:     end loop;
                    113:     if inter                              -- lift out the interior points
                    114:      then Constant_Lifting(inner,nexli,lifted,lifted_last);
                    115:     end if;
                    116:   exception
                    117:     when numeric_error  -- probably due to a too high lifting
                    118:        => Flatten(t);
                    119:           Dynamic_Lifting(rest,order,inter,maxli,lifted,lifted_last,t);
                    120:   end Dynamic_Lifting;
                    121:
                    122:   procedure Dynamic_Lifting_with_Flat
                    123:                 ( l : in List; order,inter : in boolean;
                    124:                   maxli : in natural; lifted,lifted_last : in out List;
                    125:                   t : in out Triangulation ) is
                    126:
                    127:     rest,inner : List;
                    128:     pt : Link_to_Vector;
                    129:     nexli : natural := 1;
                    130:
                    131:   begin
                    132:     Initialize(l,order,rest,lifted,lifted_last,t);
                    133:    -- ITERATE FOR ALL POINTS IN rest :
                    134:     while not Is_Null(rest) loop
                    135:       Next_Point(rest,order,pt);
                    136:       declare
                    137:         point : Link_to_Vector := new Vector(1..pt'last+1);
                    138:       begin
                    139:         point(1..pt'last) := pt.all;
                    140:         point(point'last) := 1; -- try to obtain an optimal lifting value !!
                    141:         if inter and then Is_In(t,point.all)
                    142:          then Clear(point); Construct(pt,inner);
                    143:          else nexli := Lift_to_Place(t,point.all);
                    144:               if (maxli > 0) and then (nexli > maxli)
                    145:                then Before_Flattening(t,lifted); Flatten(t);
                    146:                     nexli := 1;
                    147:               end if;
                    148:               point(point'last) := nexli;
                    149:               Update(t,point);
                    150:               Append(lifted,lifted_last,point);
                    151:         end if;
                    152:       end;
                    153:     end loop;
                    154:     if inter                               -- lift out the interior points
                    155:      then Constant_Lifting(inner,nexli,lifted,lifted_last);
                    156:     end if;
                    157:   exception
                    158:     when numeric_error    -- probably due to a too high lifting
                    159:        => Before_Flattening(t,lifted); Flatten(t);
                    160:           Dynamic_Lifting_with_Flat
                    161:              (rest,order,inter,maxli,lifted,lifted_last,t);
                    162:   end Dynamic_Lifting_with_Flat;
                    163:
                    164:   procedure Dynamic_Lifting_with_New
                    165:                 ( l : in List; order,inter : in boolean;
                    166:                   maxli : in natural; lifted,lifted_last : in out List;
                    167:                   t : in out Triangulation ) is
                    168:
                    169:     rest,inner : List;
                    170:     pt : Link_to_Vector;
                    171:     nexli : natural := 1;
                    172:     newt : Triangulation;
                    173:
                    174:   begin
                    175:     Initialize(l,order,rest,lifted,lifted_last,t);
                    176:    -- ITERATE FOR ALL POINTS IN rest :
                    177:     while not Is_Null(rest) loop
                    178:       Next_Point(rest,order,pt);
                    179:       declare
                    180:         point : Link_to_Vector := new Vector(1..pt'last+1);
                    181:       begin
                    182:         point(1..pt'last) := pt.all;
                    183:         point(point'last) := 1; -- try to obtain an optimal lifting value !!
                    184:         if inter and then Is_In(t,point.all)
                    185:          then Clear(point);  Construct(pt,inner);
                    186:          else nexli := Lift_to_Place(t,point.all);
                    187:               if (maxli > 0) and then (nexli > maxli)
                    188:                then Flatten(t);
                    189:                     nexli := 1;
                    190:               end if;
                    191:               point(point'last) := nexli;
                    192:               Update(t,point,newt);
                    193:               Process_New_Simplices(newt,point.all);
                    194:               Append(lifted,lifted_last,point);
                    195:         end if;
                    196:       end;
                    197:     end loop;
                    198:     if inter                               -- lift out the interior points
                    199:      then Constant_Lifting(inner,nexli,lifted,lifted_last);
                    200:     end if;
                    201:   exception
                    202:     when numeric_error    -- probably due to a too high lifting
                    203:        => Flatten(t);
                    204:           Dynamic_Lifting_with_New(rest,order,inter,maxli,lifted,lifted_last,t);
                    205:   end Dynamic_Lifting_with_New;
                    206:
                    207:   procedure Dynamic_Lifting_with_Flat_and_New
                    208:                 ( l : in List; order,inter : in boolean;
                    209:                   maxli : in natural; lifted,lifted_last : in out List;
                    210:                   t : in out Triangulation ) is
                    211:
                    212:     rest,last,inner : List;
                    213:     pt : Link_to_Vector;
                    214:     nexli : natural := 1;
                    215:     newt : Triangulation;
                    216:
                    217:   begin
                    218:     Initialize(l,order,rest,lifted,lifted_last,t);
                    219:    -- ITERATE FOR ALL POINTS IN rest :
                    220:     while not Is_Null(rest) loop
                    221:       Next_Point(rest,order,pt);
                    222:       declare
                    223:         point : Link_to_Vector := new Vector(1..pt'last+1);
                    224:       begin
                    225:         point(1..pt'last) := pt.all;
                    226:         point(point'last) := 1; -- try to obtain an optimal lifting value !!
                    227:         if inter and then Is_In(t,point.all)
                    228:          then Clear(point);  Construct(pt,inner);
                    229:          else nexli := Lift_to_Place(t,point.all);
                    230:               if (maxli > 0) and then (nexli > maxli)
                    231:                then Before_Flattening(t,lifted); Flatten(t);
                    232:                     nexli := 1;
                    233:               end if;
                    234:               point(point'last) := nexli;
                    235:               Update(t,point,newt);
                    236:               Process_New_Simplices(newt,point.all);
                    237:               Append(lifted,lifted_last,point);
                    238:         end if;
                    239:       end;
                    240:     end loop;
                    241:     if inter                               -- lift out the interior points
                    242:      then Constant_Lifting(inner,nexli,lifted,lifted_last);
                    243:     end if;
                    244:   exception
                    245:     when numeric_error    -- probably due to a too high lifting
                    246:        => Before_Flattening(t,lifted); Flatten(t);
                    247:           Dynamic_Lifting_with_Flat_and_New
                    248:              (rest,order,inter,maxli,lifted,lifted_last,t);
                    249:   end Dynamic_Lifting_with_Flat_and_New;
                    250:
                    251: end Dynamic_Triangulations;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>