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