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