001 /*
002 * $Id: SolvableGroebnerBaseParTest.java 2412 2009-02-07 12:17:54Z kredel $
003 */
004
005 package edu.jas.gb;
006
007 import java.util.ArrayList;
008 import java.util.List;
009
010 import junit.framework.Test;
011 import junit.framework.TestCase;
012 import junit.framework.TestSuite;
013
014 import org.apache.log4j.BasicConfigurator;
015 //import org.apache.log4j.Logger;
016
017 import edu.jas.arith.BigRational;
018 import edu.jas.poly.GenSolvablePolynomial;
019 import edu.jas.poly.GenSolvablePolynomialRing;
020 import edu.jas.poly.PolynomialList;
021 import edu.jas.poly.RelationTable;
022 import edu.jas.poly.TermOrder;
023 import edu.jas.poly.WeylRelations;
024
025 /**
026 * SolvableGroebnerBase parallel tests with JUnit.
027 * @author Heinz Kredel.
028 */
029
030 public class SolvableGroebnerBaseParTest extends TestCase {
031
032 //private static final Logger logger = Logger.getLogger(SolvableGroebnerBaseParTest.class);
033
034 /**
035 * main.
036 */
037 public static void main (String[] args) {
038 BasicConfigurator.configure();
039 junit.textui.TestRunner.run( suite() );
040 }
041
042 /**
043 * Constructs a <CODE>SolvableGroebnerBaseParTest</CODE> object.
044 * @param name String.
045 */
046 public SolvableGroebnerBaseParTest(String name) {
047 super(name);
048 }
049
050 /**
051 * suite.
052 */
053 public static Test suite() {
054 TestSuite suite= new TestSuite(SolvableGroebnerBaseParTest.class);
055 return suite;
056 }
057
058 int port = 4711;
059 String host = "localhost";
060
061 GenSolvablePolynomial<BigRational> a;
062 GenSolvablePolynomial<BigRational> b;
063 GenSolvablePolynomial<BigRational> c;
064 GenSolvablePolynomial<BigRational> d;
065 GenSolvablePolynomial<BigRational> e;
066
067 List<GenSolvablePolynomial<BigRational>> L;
068 PolynomialList<BigRational> F;
069 PolynomialList<BigRational> G;
070
071 GenSolvablePolynomialRing<BigRational> ring;
072
073 SolvableGroebnerBase<BigRational> psbb;
074
075 BigRational cfac;
076 TermOrder tord;
077 RelationTable<BigRational> table;
078
079 int rl = 4; //4; //3;
080 int kl = 10;
081 int ll = 4;
082 int el = 2;
083 float q = 0.3f; //0.4f
084
085 protected void setUp() {
086 cfac = new BigRational(9);
087 tord = new TermOrder();
088 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rl,tord);
089 table = ring.table;
090 a = b = c = d = e = null;
091 psbb = new SolvableGroebnerBaseParallel<BigRational>();
092
093 a = ring.random(kl, ll, el, q );
094 b = ring.random(kl, ll, el, q );
095 c = ring.random(kl, ll, el, q );
096 d = ring.random(kl, ll, el, q );
097 e = d; //ring.random(kl, ll, el, q );
098 }
099
100 protected void tearDown() {
101 a = b = c = d = e = null;
102 ring = null;
103 tord = null;
104 table = null;
105 cfac = null;
106 ((SolvableGroebnerBaseParallel<BigRational>)psbb).terminate();
107 psbb = null;
108 }
109
110
111 /**
112 * Test parallel GBase.
113 */
114 public void testParallelGBase() {
115
116 assertTrue("not isZERO( a )", !a.isZERO() );
117
118 L = new ArrayList<GenSolvablePolynomial<BigRational>>();
119 L.add(a);
120
121 L = psbb.leftGB( L );
122 assertTrue("isLeftGB( { a } )", psbb.isLeftGB(L) );
123
124 assertTrue("not isZERO( b )", !b.isZERO() );
125 L.add(b);
126 //System.out.println("L = " + L.size() );
127
128 L = psbb.leftGB( L );
129 assertTrue("isLeftGB( { a, b } )", psbb.isLeftGB(L) );
130
131 assertTrue("not isZERO( c )", !c.isZERO() );
132 L.add(c);
133
134 L = psbb.leftGB( L );
135 assertTrue("isLeftGB( { a, b, c } )", psbb.isLeftGB(L) );
136
137 assertTrue("not isZERO( d )", !d.isZERO() );
138 L.add(d);
139
140 L = psbb.leftGB( L );
141 assertTrue("isLeftGB( { a, b, c, d } )", psbb.isLeftGB(L) );
142
143 assertTrue("not isZERO( e )", !e.isZERO() );
144 L.add(e);
145
146 L = psbb.leftGB( L );
147 assertTrue("isLeftGB( { a, b, c, d, e } )", psbb.isLeftGB(L) );
148 }
149
150
151 /**
152 * Test Weyl parallel GBase.
153 *
154 */
155 public void testWeylParallelGBase() {
156
157 int rloc = 4;
158 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rloc);
159
160 WeylRelations<BigRational> wl = new WeylRelations<BigRational>(ring);
161 wl.generate();
162 table = ring.table;
163
164 a = ring.random(kl, ll, el, q );
165 b = ring.random(kl, ll, el, q );
166 c = ring.random(kl, ll, el, q );
167 d = ring.random(kl, ll, el, q );
168 e = d; //ring.random(kl, ll, el, q );
169
170 assertTrue("not isZERO( a )", !a.isZERO() );
171
172 L = new ArrayList<GenSolvablePolynomial<BigRational>>();
173 L.add(a);
174
175 L = psbb.leftGB( L );
176 assertTrue("isLeftGB( { a } )", psbb.isLeftGB(L) );
177
178 assertTrue("not isZERO( b )", !b.isZERO() );
179 L.add(b);
180 //System.out.println("L = " + L.size() );
181
182 L = psbb.leftGB( L );
183 assertTrue("isLeftGB( { a, b } )", psbb.isLeftGB(L) );
184
185 assertTrue("not isZERO( c )", !c.isZERO() );
186 L.add(c);
187
188 L = psbb.leftGB( L );
189 assertTrue("isLeftGB( { a, b, c } )", psbb.isLeftGB(L) );
190
191 assertTrue("not isZERO( d )", !d.isZERO() );
192 L.add(d);
193
194 L = psbb.leftGB( L );
195 assertTrue("isLeftGB( { a, b, c, d } )", psbb.isLeftGB(L) );
196
197 assertTrue("not isZERO( e )", !e.isZERO() );
198 L.add(e);
199
200 L = psbb.leftGB( L );
201 assertTrue("isLeftGB( { a, b, c, d, e } )", psbb.isLeftGB(L) );
202 }
203
204
205 /**
206 * Test parallel twosided GBase.
207 *
208 */
209 public void testParallelTSGBase() {
210
211 assertTrue("not isZERO( a )", !a.isZERO() );
212
213 L = new ArrayList<GenSolvablePolynomial<BigRational>>();
214 L.add(a);
215
216 L = psbb.twosidedGB( L );
217 //System.out.println("L = " + L.size() );
218 assertTrue("isTwosidedGB( { a } )", psbb.isTwosidedGB(L) );
219
220 assertTrue("not isZERO( b )", !b.isZERO() );
221 L.add(b);
222
223 L = psbb.twosidedGB( L );
224 //System.out.println("L = " + L.size() );
225 assertTrue("isTwosidedGB( { a, b } )", psbb.isTwosidedGB(L) );
226
227 assertTrue("not isZERO( c )", !c.isZERO() );
228 L.add(c);
229
230 L = psbb.twosidedGB( L );
231 //System.out.println("L = " + L.size() );
232 assertTrue("isTwosidedGB( { a, b, c } )", psbb.isTwosidedGB(L) );
233
234 assertTrue("not isZERO( d )", !d.isZERO() );
235 L.add(d);
236
237 L = psbb.twosidedGB( L );
238 //System.out.println("L = " + L.size() );
239 assertTrue("isTwosidedGB( { a, b, c, d } )", psbb.isTwosidedGB(L) );
240
241 assertTrue("not isZERO( e )", !e.isZERO() );
242 L.add(e);
243
244 L = psbb.twosidedGB( L );
245 //System.out.println("L = " + L.size() );
246 assertTrue("isTwosidedGB( { a, b, c, d, e } )", psbb.isTwosidedGB(L) );
247 }
248
249
250
251 /**
252 * Test Weyl parallel twosided GBase
253 * is always 1.
254 */
255 public void testWeylParallelTSGBase() {
256
257 int rloc = 4;
258 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rloc);
259
260 WeylRelations<BigRational> wl = new WeylRelations<BigRational>(ring);
261 wl.generate();
262 table = ring.table;
263
264 a = ring.random(kl, ll, el, q );
265 b = ring.random(kl, ll, el, q );
266 c = ring.random(kl, ll, el, q );
267 d = ring.random(kl, ll, el, q );
268 e = d; //ring.random(kl, ll, el, q );
269
270 assertTrue("not isZERO( a )", !a.isZERO() );
271
272 L = new ArrayList<GenSolvablePolynomial<BigRational>>();
273 L.add(a);
274
275 //System.out.println("La = " + L );
276 L = psbb.twosidedGB( L );
277 //System.out.println("L = " + L );
278 assertTrue("isTwosidedGB( { a } )", psbb.isTwosidedGB(L) );
279
280 assertTrue("not isZERO( b )", !b.isZERO() );
281 L.add(b);
282
283 L = psbb.twosidedGB( L );
284 //System.out.println("L = " + L );
285 assertTrue("isTwosidedGB( { a, b } )", psbb.isTwosidedGB(L) );
286
287 assertTrue("not isZERO( c )", !c.isZERO() );
288 L.add(c);
289
290 L = psbb.twosidedGB( L );
291 //System.out.println("L = " + L );
292 assertTrue("isTwosidedGB( { a, b, c } )", psbb.isTwosidedGB(L) );
293
294 assertTrue("not isZERO( d )", !d.isZERO() );
295 L.add(d);
296
297 L = psbb.twosidedGB( L );
298 //System.out.println("L = " + L );
299 assertTrue("isTwosidedGB( { a, b, c, d } )", psbb.isTwosidedGB(L) );
300
301 assertTrue("not isZERO( e )", !e.isZERO() );
302 L.add(e);
303
304 L = psbb.twosidedGB( L );
305 //System.out.println("L = " + L );
306 assertTrue("isTwosidedGB( { a, b, c, d, e } )", psbb.isTwosidedGB(L) );
307 }
308
309 }