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