001/* 002 * $Id: GroebnerBasePseudoParTest.java 5865 2018-07-20 14:35:30Z kredel $ 003 */ 004 005package edu.jas.gbufd; 006 007 008import java.io.IOException; 009import java.io.Reader; 010import java.io.StringReader; 011import java.util.ArrayList; 012import java.util.List; 013 014import junit.framework.Test; 015import junit.framework.TestCase; 016import junit.framework.TestSuite; 017 018 019import edu.jas.arith.BigInteger; 020import edu.jas.gb.GroebnerBaseAbstract; 021import edu.jas.poly.GenPolynomial; 022import edu.jas.poly.GenPolynomialRing; 023import edu.jas.poly.GenPolynomialTokenizer; 024import edu.jas.poly.PolynomialList; 025 026 027/** 028 * Groebner base pseudo reduction parallel tests with JUnit. 029 * @author Heinz Kredel 030 */ 031 032public class GroebnerBasePseudoParTest extends TestCase { 033 034 035 /** 036 * main 037 */ 038 public static void main(String[] args) { 039 junit.textui.TestRunner.run(suite()); 040 } 041 042 043 /** 044 * Constructs a <CODE>GroebnerBasePseudoParTest</CODE> object. 045 * @param name String. 046 */ 047 public GroebnerBasePseudoParTest(String name) { 048 super(name); 049 } 050 051 052 /** 053 * suite. 054 */ 055 public static Test suite() { 056 TestSuite suite = new TestSuite(GroebnerBasePseudoParTest.class); 057 return suite; 058 } 059 060 061 GenPolynomialRing<BigInteger> fac; 062 063 064 List<GenPolynomial<BigInteger>> L; 065 066 067 PolynomialList<BigInteger> F; 068 069 070 List<GenPolynomial<BigInteger>> G; 071 072 073 GroebnerBaseAbstract<BigInteger> bb; 074 075 076 GenPolynomial<BigInteger> a; 077 078 079 GenPolynomial<BigInteger> b; 080 081 082 GenPolynomial<BigInteger> c; 083 084 085 GenPolynomial<BigInteger> d; 086 087 088 GenPolynomial<BigInteger> e; 089 090 091 int rl = 3; //4; //3; 092 093 094 int kl = 10; 095 096 097 int ll = 7; 098 099 100 int el = 3; 101 102 103 float q = 0.2f; //0.4f 104 105 106 int threads = 2; 107 108 109 @Override 110 protected void setUp() { 111 BigInteger coeff = new BigInteger(9); 112 fac = new GenPolynomialRing<BigInteger>(coeff, rl); 113 a = b = c = d = e = null; 114 bb = new GroebnerBasePseudoParallel<BigInteger>(threads, coeff); 115 } 116 117 118 @Override 119 protected void tearDown() { 120 a = b = c = d = e = null; 121 fac = null; 122 bb.terminate(); 123 bb = null; 124 } 125 126 127 /** 128 * Test parallel GBase. 129 * 130 */ 131 public void testParallelGBase() { 132 133 L = new ArrayList<GenPolynomial<BigInteger>>(); 134 135 a = fac.random(kl, ll, el, q); 136 b = fac.random(kl, ll, el, q); 137 c = fac.random(kl, ll, el, q); 138 d = fac.random(kl, ll, el, q); 139 e = d; //fac.random(kl, ll, el, q ); 140 141 //if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) { 142 // return; 143 //} 144 145 L.add(a); 146 L = bb.GB(L); 147 assertTrue("isGB( { a } )", bb.isGB(L)); 148 149 L.add(b); 150 //System.out.println("L = " + L.size() ); 151 L = bb.GB(L); 152 assertTrue("isGB( { a, b } )", bb.isGB(L)); 153 154 L.add(c); 155 L = bb.GB(L); 156 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 157 158 L.add(d); 159 L = bb.GB(L); 160 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 161 162 L.add(e); 163 L = bb.GB(L); 164 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 165 } 166 167 168 /** 169 * Test Trinks6/7 GBase. 170 * 171 */ 172 @SuppressWarnings("unchecked") 173 public void testTrinks7GBase() { 174 String exam = "Z(B,S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - 165 B - 36 ), " 175 + "( 35 P + 40 Z + 25 T - 27 S ), " + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), " 176 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - 11 B**3 ), " 177 + "( 99 W - 11 B S + 3 B**2 ), " 178 //+ "( 10000 B**2 + 6600 B + 2673 ) " 179 + ") "; 180 Reader source = new StringReader(exam); 181 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 182 try { 183 F = (PolynomialList<BigInteger>) parser.nextPolynomialSet(); 184 } catch (ClassCastException e) { 185 fail("" + e); 186 } catch (IOException e) { 187 fail("" + e); 188 } 189 //System.out.println("F = " + F); 190 191 long s, t; 192 t = System.currentTimeMillis(); 193 G = bb.GB(F.list); 194 t = System.currentTimeMillis() - t; 195 assertTrue("isGB( GB(Trinks7) )", bb.isGB(G)); 196 assertEquals("#GB(Trinks7) == 6", 6, G.size()); 197 PolynomialList<BigInteger> Gpl = new PolynomialList<BigInteger>(F.ring, G); 198 //System.out.println("G = " + Gpl); 199 assertTrue("nonsense ", t >= 0L); 200 201 GenPolynomialRing<BigInteger> ifac = F.ring; 202 203 List<GenPolynomial<BigInteger>> Gi; 204 GroebnerBasePseudoSeq<BigInteger> bbr = new GroebnerBasePseudoSeq<BigInteger>(ifac.coFac); 205 s = System.currentTimeMillis(); 206 Gi = bbr.GB(F.list); 207 s = System.currentTimeMillis() - s; 208 PolynomialList<BigInteger> Gipl = new PolynomialList<BigInteger>(F.ring, Gi); 209 //System.out.println("G = " + Gpl); 210 //System.out.println("Gi = " + Gipl); 211 212 assertEquals("seqGB == parGB", Gpl, Gipl); 213 //System.out.println("time: seqGB = " + s + ", parGB = " + t); 214 assertTrue("nonsense ", s >= 0L); 215 } 216 217}