Annotation of OpenXM_contrib/PHC/Ada/Root_Counts/Product/drivers_for_m_homogenization.adb, Revision 1.1.1.1
1.1 maekawa 1: with integer_io; use integer_io;
2: with Communications_with_User; use Communications_with_User;
3: with Numbers_io; use Numbers_io;
4: with Timing_Package; use Timing_Package;
5: with Standard_Complex_Poly_Systems_io; use Standard_Complex_Poly_Systems_io;
6: with Standard_Complex_Solutions_io; use Standard_Complex_Solutions_io;
7: with Sets_of_Unknowns; use Sets_of_Unknowns;
8: with Sets_of_Unknowns_io; use Sets_of_Unknowns_io;
9: with Partitions_of_Sets_of_Unknowns; use Partitions_of_Sets_of_Unknowns;
10: with Partitions_of_Sets_of_Unknowns_io; use Partitions_of_Sets_of_Unknowns_io;
11: with m_Homogeneous_Bezout_Numbers; use m_Homogeneous_Bezout_Numbers;
12: with m_Homogeneous_Start_Systems; use m_Homogeneous_Start_Systems;
13: with Interpolating_Homotopies_Driver;
14:
15: package body Drivers_for_m_Homogenization is
16:
17: procedure m_Homogenization_Info is
18:
19: i : array(1..15) of string(1..65);
20:
21: begin
22: i( 1):=" An m-homogeneous Bezout number is based on a partition of the";
23: i( 2):="set of unknowns, with m the number of sets in the partition. ";
24: i( 3):=" The corresponding start system is a linear-product system: the";
25: i( 4):="i-th equation is the product of linear equations with random";
26: i( 5):="coefficients in the unknowns of the set of the partition. The";
27: i( 6):="number of factors in the product of the i-th polynomial equals";
28: i( 7):="the product of the degrees of the i-th polynomial in the original";
29: i( 8):="system w.r.t. every set in the partition. ";
30: i( 9):=" Given a partition, the m-homogeneous Bezout number equals the";
31: i(10):="number of solutions of the corresponding linear-product start";
32: i(11):="system. Before the construction of the start system, an m-";
33: i(12):="homogeneous Bezout number is first computed in a formal way as a";
34: i(13):="generalized permanent of a degree matrix. Either all partitions";
35: i(14):="of the set of unknowns can be evaluated, or the available";
36: i(15):="heuristic procedure for generating a partition can be applied. ";
37: for k in i'range loop
38: put_line(i(k));
39: end loop;
40: end m_Homogenization_Info;
41:
42: procedure Driver_for_m_Homogenization
43: ( file : in file_type; p : in Poly_Sys; b : in out natural;
44: q : out Poly_Sys; qsols : out Solution_List ) is
45:
46: n : natural := p'length;
47: np : constant natural := Number_of_Partitions(n);
48:
49: procedure Write_Results ( file : in file_type;
50: bz,nz : in natural; z : in partition ) is
51: begin
52: new_line(file);
53: put(file," "); put(file,nz,1);
54: put(file,"-homogeneous Bezout number is "); put(file,bz,1);
55: new_line(file);
56: put(file," with partition : "); put(file,z); new_line(file);
57: end Write_Results;
58:
59: procedure Save_Results ( qq : in Poly_Sys; qqsols : in Solution_List ) is
60:
61: qqfile : file_type;
62:
63: begin
64: if not Is_Null(qqsols)
65: then new_line;
66: put_line("Reading file name to write start system.");
67: Read_Name_and_Create_File(qqfile);
68: put_line(qqfile,qq);
69: new_line(qqfile);
70: put_line(qqfile,"THE SOLUTIONS : ");
71: new_line(qqfile);
72: put(qqfile,Length_Of(qqsols),Head_Of(qqsols).n,qqsols);
73: Close(qqfile);
74: end if;
75: end Save_Results;
76:
77: function Universe ( n : natural ) return Set is
78:
79: -- DESCRIPTION : Returns the set of all unknowns.
80:
81: s : Set := Create(n);
82:
83: begin
84: for i in 1..n loop
85: Add(s,i);
86: end loop;
87: return s;
88: end Universe;
89:
90: procedure Display_Menu
91: ( choice : out character;
92: bz,nz : in natural; z : in Partition ) is
93:
94: ans : character;
95:
96: begin
97: new_line;
98: put_line("MENU for computing m-Homogeneous Bezout Numbers :");
99: put (" 0. exit - Bezout number : ");
100: put(bz,1); put(", partition : "); put(z(1..nz)); new_line;
101: put_line(" 1. Heuristic generation of a partition");
102: put (" 2. Enumerate all "); put(np,1); put_line(" partitions");
103: put_line(" 3. Enumerate over #partitions <= given maximum");
104: put_line(" 4. Enumerate till Bezout number <= given minimum");
105: put_line(" 5. Combine stop criteria of strategies 3 and 4");
106: put_line(" 6. Evaluate your own partition");
107: put("Type number between 0 and 6 to choose : ");
108: Ask_Alternative(ans,"0123456"); choice := ans;
109: end Display_Menu;
110:
111: procedure Dispatch_Menu
112: ( file : in file_type; choice : in character;
113: bz,nz : in out natural; z : in out Partition ) is
114:
115: -- DESCRIPTION :
116: -- Dispatches the choice of the user.
117:
118: -- ON ENTRY :
119: -- file must be opened for output;
120: -- choice choice of method;
121: -- bz current Bezout number with partition z;
122: -- nz number of sets in current partition z;
123: -- z current partition is z(1..nz).
124:
125: max,min : natural;
126:
127: begin
128: new_line(file);
129: case choice is
130: when '1' => Clear(z); nz := 0;
131: put_line(file,"HEURISTIC PARTITIONER :");
132: PB(p,bz,nz,z);
133: when '2' => put(file,"ENUMERATION OF ");
134: put(file,np,1); put_line(file," PARTITIONS :");
135: Bezout_number(p,bz,nz,z);
136: when '3' => put(" Give maximum bound : "); Read_Natural(max);
137: put(file,"ENUMERATION OF ");
138: put(file,max,1); put_line(file," PARTITIONS :");
139: Bezout_number(max,p,bz,nz,z);
140: when '4' => put(" Give minimum bound : "); Read_Natural(min);
141: put(file,"ENUMERATION TILL BEZOUT NUMBER <= ");
142: put(file,min,1); new_line(file);
143: Bezout_number(p,min,bz,nz,z);
144: when '5' => put(" Give maximum bound : "); Read_Natural(max);
145: put(" Give minimum bound : "); Read_Natural(min);
146: put(file,"ENUMERATION OF ");
147: put(file,max,1); put_line(file," PARTITIONS");
148: put(file," OR TILL BEZOUT NUMBER <= ");
149: put(file,min,1); new_line(file);
150: Bezout_number(max,p,min,bz,nz,z);
151: when '6' => Clear(z); nz := 0;
152: put_line(file,"PARTITION PROVIDED BY USER :");
153: put("Give the number of sets : "); Read_Positive(nz);
154: put("Give "); put(nz,1); put(" sets : ");
155: Create(z,n); get(z(1..nz));
156: bz := Bezout_Number(p,z);
157: when others => null;
158: end case;
159: Write_Results(file,bz,nz,z(1..nz));
160: Write_Results(Standard_Output,bz,nz,z(1..nz));
161: end Dispatch_Menu;
162:
163: procedure Driver_for_Partition
164: ( file : in file_type;
165: bz,nz : in out natural; z : in out Partition ) is
166:
167: method : character;
168: timer : timing_widget;
169:
170: begin
171: new_line(file);
172: put_line(file,"M-HOMOGENIZATION :");
173: tstart(timer);
174: loop
175: Display_Menu(method,bz,nz,z);
176: exit when method = '0';
177: Dispatch_Menu(file,method,bz,nz,z);
178: end loop;
179: tstop(timer);
180: new_line(file);
181: print_times(file,timer,"Computation of m-homogeneous Bezout number");
182: end Driver_for_Partition;
183:
184: procedure Driver_for_Start_System
185: ( file : in file_type; bz : in natural; z : in Partition ) is
186:
187: ans : character;
188: timer : timing_widget;
189: qq : Poly_Sys(p'range);
190: qqsols : Solution_List;
191: bb : natural := bz;
192:
193: begin
194: new_line;
195: put_line("MENU for m-Homogeneous Start Systems :");
196: put_line(" 0. No construction of m-homogeneous start system.");
197: put_line(" 1. Start system based on interpolation.");
198: put_line(" 2. Random linear-product start system.");
199: put("Type 0,1, or 2 to choose : "); Ask_Alternative(ans,"012");
200: if ans /= '0'
201: then tstart(timer);
202: if ans = '1'
203: then Interpolating_Homotopies_Driver(file,p,z,bb,qq,qqsols);
204: else m_Homogeneous_Start_System(p,z,qq,qqsols);
205: end if;
206: tstop(timer);
207: Save_Results(qq,qqsols);
208: q := qq; qsols := qqsols;
209: new_line(file);
210: put(file,z'last,1);
211: put_line(file,"-HOMOGENEOUS START SYSTEM : ");
212: put_line(file,qq);
213: new_line(file);
214: put_line(file,"THE SOLUTIONS :");
215: new_line(file);
216: put(file,Length_Of(qqsols),Head_Of(qqsols).n,qqsols);
217: new_line(file);
218: print_times(file,timer,
219: "Construction of m-homogeneous start system");
220: end if;
221: end Driver_for_Start_System;
222:
223: procedure Main_Driver is
224:
225: z : Partition(1..n);
226: bz,nz : natural;
227:
228: begin
229: nz := 1; z(1) := Universe(n); bz := Total_Degree(p);
230: Driver_for_Partition(file,bz,nz,z);
231: Driver_for_Start_System(file,bz,z(1..nz));
232: b := bz;
233: end Main_Driver;
234:
235: begin
236: Main_Driver;
237: end Driver_for_m_Homogenization;
238:
239: end Drivers_for_m_Homogenization;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>