001/* 002 * $Id: GroebnerBaseDistHybridECTest.java 4242 2012-10-07 08:48:00Z kredel $ 003 */ 004 005package edu.jas.gb; 006 007 008//import edu.jas.poly.GroebnerBase; 009 010import java.io.IOException; 011import java.io.Reader; 012import java.io.StringReader; 013import java.util.ArrayList; 014import java.util.List; 015 016import junit.framework.Test; 017import junit.framework.TestCase; 018import junit.framework.TestSuite; 019 020import org.apache.log4j.BasicConfigurator; //import org.apache.log4j.Logger; 021 022import edu.jas.kern.ComputerThreads; 023import edu.jas.arith.BigRational; 024import edu.jas.poly.GenPolynomial; 025import edu.jas.poly.GenPolynomialRing; 026import edu.jas.poly.GenPolynomialTokenizer; 027import edu.jas.poly.PolynomialList; 028import edu.jas.structure.RingElem; 029import edu.jas.util.ExecutableServer; 030 031 032/** 033 * Distributed hybrid GroebnerBase tests with JUnit. 034 * @author Heinz Kredel 035 */ 036 037public class GroebnerBaseDistHybridECTest extends TestCase { 038 039 040 //private static final Logger logger = Logger.getLogger(GroebnerBaseDistHybridECTest.class); 041 042 /** 043 * main 044 */ 045 public static void main(String[] args) { 046 BasicConfigurator.configure(); 047 junit.textui.TestRunner.run(suite()); 048 //ComputerThreads.terminate(); 049 } 050 051 052 /** 053 * Constructs a <CODE>GroebnerBaseDistHybridECTest</CODE> object. 054 * @param name String. 055 */ 056 public GroebnerBaseDistHybridECTest(String name) { 057 super(name); 058 } 059 060 061 /** 062 * suite. 063 */ 064 public static Test suite() { 065 TestSuite suite = new TestSuite(GroebnerBaseDistHybridECTest.class); 066 return suite; 067 } 068 069 070 int port = 55711; 071 072 073 String host = "localhost"; 074 075 076 String mfile = "examples/machines.localhost"; // contains localhost 077 078 079 GenPolynomialRing<BigRational> fac; 080 081 082 List<GenPolynomial<BigRational>> L; 083 084 085 PolynomialList<BigRational> F; 086 087 088 List<GenPolynomial<BigRational>> G; 089 090 091 GroebnerBase<BigRational> bbseq; 092 093 094 GroebnerBaseAbstract<BigRational> bbdist; 095 096 097 GroebnerBaseAbstract<BigRational> bbdists; 098 099 100 GenPolynomial<BigRational> a; 101 102 103 GenPolynomial<BigRational> b; 104 105 106 GenPolynomial<BigRational> c; 107 108 109 GenPolynomial<BigRational> d; 110 111 112 GenPolynomial<BigRational> e; 113 114 115 int rl = 3; //4; //3; 116 117 118 int kl = 4; 119 120 121 int ll = 7; 122 123 124 int el = 3; 125 126 127 float q = 0.2f; //0.4f 128 129 130 int threads = 2; 131 132 133 ExecutableServer es1; 134 135 136 ExecutableServer es2; 137 138 139 @Override 140 protected void setUp() { 141 es1 = new ExecutableServer(4712); // == machines.localhost:4712 142 es1.init(); 143 es2 = new ExecutableServer(4711); // == machines.localhost:4711 144 es2.init(); 145 BigRational coeff = new BigRational(9); 146 fac = new GenPolynomialRing<BigRational>(coeff, rl); 147 a = b = c = d = e = null; 148 bbseq = new GroebnerBaseSeq<BigRational>(); 149 bbdist = new GroebnerBaseDistributedHybridEC<BigRational>(mfile, threads, port); 150 //bbdists = new GroebnerBaseDistributedHybridEC<BigRational>(mfile, threads, new OrderedSyzPairlist<BigRational>(), port); 151 } 152 153 154 @Override 155 protected void tearDown() { 156 a = b = c = d = e = null; 157 fac = null; 158 bbseq = null; 159 bbdist.terminate(); 160 bbdist = null; 161 //bbdists.terminate(); 162 //bbdists = null; 163 es1.terminate(); 164 es2.terminate(); 165 es1 = null; 166 es2 = null; 167 ComputerThreads.terminate(); 168 } 169 170 171 /** 172 * Test distributed GBase. 173 */ 174 public void testDistributedGBase() { 175 L = new ArrayList<GenPolynomial<BigRational>>(); 176 177 a = fac.random(kl, ll, el, q); 178 b = fac.random(kl, ll, el, q); 179 c = fac.random(kl, ll, el, q); 180 d = fac.random(kl, ll, el, q); 181 e = d; //fac.random(kl, ll, el, q ); 182 183 L.add(a); 184 L = bbdist.GB(L); 185 assertTrue("isGB( { a } )", bbseq.isGB(L)); 186 187 L.add(b); 188 //System.out.println("L = " + L.size() ); 189 L = bbdist.GB(L); 190 assertTrue("isGB( { a, b } )", bbseq.isGB(L)); 191 192 L.add(c); 193 L = bbdist.GB(L); 194 assertTrue("isGB( { a, b, c } )", bbseq.isGB(L)); 195 196 L.add(d); 197 L = bbdist.GB(L); 198 assertTrue("isGB( { a, b, c, d } )", bbseq.isGB(L)); 199 200 L.add(e); 201 L = bbdist.GB(L); 202 assertTrue("isGB( { a, b, c, d, e } )", bbseq.isGB(L)); 203 } 204 205 206 /** 207 * Test compare sequential with distributed GBase. 208 */ 209 public void testSequentialDistributedGBase() { 210 List<GenPolynomial<BigRational>> Gs, Gp = null; 211 L = new ArrayList<GenPolynomial<BigRational>>(); 212 213 a = fac.random(kl, ll, el, q); 214 b = fac.random(kl, ll, el, q); 215 c = fac.random(kl, ll, el, q); 216 d = fac.random(kl, ll, el, q); 217 e = d; //fac.random(kl, ll, el, q ); 218 219 L.add(a); 220 Gs = bbseq.GB(L); 221 Gp = bbdist.GB(L); 222 assertTrue("Gs.containsAll(Gp)" + Gs + ", " + Gp + ", " + L, Gs.containsAll(Gp)); 223 assertTrue("Gp.containsAll(Gs)" + Gs + ", " + Gp + ", " + L, Gp.containsAll(Gs)); 224 225 L = Gs; 226 L.add(b); 227 Gs = bbseq.GB(L); 228 Gp = bbdist.GB(L); 229 assertTrue("Gs.containsAll(Gp)" + Gs + ", " + Gp + ", " + L, Gs.containsAll(Gp)); 230 assertTrue("Gp.containsAll(Gs)" + Gs + ", " + Gp + ", " + L, Gp.containsAll(Gs)); 231 232 L = Gs; 233 L.add(c); 234 Gs = bbseq.GB(L); 235 Gp = bbdist.GB(L); 236 assertTrue("Gs.containsAll(Gp)" + Gs + ", " + Gp + ", " + L, Gs.containsAll(Gp)); 237 assertTrue("Gp.containsAll(Gs)" + Gs + ", " + Gp + ", " + L, Gp.containsAll(Gs)); 238 239 L = Gs; 240 L.add(d); 241 Gs = bbseq.GB(L); 242 Gp = bbdist.GB(L); 243 assertTrue("Gs.containsAll(Gp)" + Gs + ", " + Gp + ", " + L, Gs.containsAll(Gp)); 244 assertTrue("Gp.containsAll(Gs)" + Gs + ", " + Gp + ", " + L, Gp.containsAll(Gs)); 245 246 L = Gs; 247 L.add(e); 248 Gs = bbseq.GB(L); 249 Gp = bbdist.GB(L); 250 assertTrue("Gs.containsAll(Gp)" + Gs + ", " + Gp + ", " + L, Gs.containsAll(Gp)); 251 assertTrue("Gp.containsAll(Gs)" + Gs + ", " + Gp + ", " + L, Gp.containsAll(Gs)); 252 } 253 254 255 /** 256 * Test Trinks7 GBase. 257 */ 258 public void testTrinks7GBase() { 259 List<GenPolynomial<BigRational>> Gs, Gp = null; 260 String exam = "(B,S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - 165 B - 36 ), " 261 + "( 35 P + 40 Z + 25 T - 27 S ), " + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), " 262 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - 11 B**3 ), " 263 + "( 99 W - 11 B S + 3 B**2 ), " + "( B**2 + 33/50 B + 2673/10000 ) " + ") "; 264 //exam = "(x3,x4,x5) L " + 265 // "( (x3^2 - 13974703710478159/3775194259200) , (x4 - 34297/840), (x5^2 - 6389/480), (-4/3 x5^2 + x3^2 + x3 - 833/180) ) "; 266 Reader source = new StringReader(exam); 267 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 268 try { 269 F = (PolynomialList<BigRational>) parser.nextPolynomialSet(); 270 } catch (IOException e) { 271 fail("" + e); 272 } 273 //System.out.println("F = " + F); 274 275 Gp = bbdist.GB(F.list); 276 //System.out.println("Gp = " + Gp); 277 Gs = bbseq.GB(F.list); 278 //System.out.println("Gs = " + Gs); 279 280 assertTrue("isGB( GB(Trinks7) )", bbseq.isGB(Gp)); 281 assertTrue("isGB( GB(Trinks7) )", bbseq.isGB(Gs)); 282 //assertEquals("#GB(Trinks7) == 6", 6, G.size()); 283 assertTrue("Gs.containsAll(Gp)" + Gs + ", " + Gp + ", " + F, Gs.containsAll(Gp)); 284 assertTrue("Gp.containsAll(Gs)" + Gs + ", " + Gp + ", " + F, Gp.containsAll(Gs)); 285 //PolynomialList<BigRational> trinks = new PolynomialList<BigRational>(F.ring, Gp); 286 //System.out.println("G = " + trinks); 287 } 288 289}