001package conexp.fx.core.dl.deprecated;
002
003import java.util.Collection;
004
005/*-
006 * #%L
007 * Concept Explorer FX
008 * %%
009 * Copyright (C) 2010 - 2019 Francesco Kriegel
010 * %%
011 * This program is free software: you can redistribute it and/or modify
012 * it under the terms of the GNU General Public License as
013 * published by the Free Software Foundation, either version 3 of the
014 * License, or (at your option) any later version.
015 * 
016 * This program is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
019 * GNU General Public License for more details.
020 * 
021 * You should have received a copy of the GNU General Public
022 * License along with this program.  If not, see
023 * <http://www.gnu.org/licenses/gpl-3.0.html>.
024 * #L%
025 */
026
027import java.util.Deque;
028import java.util.HashSet;
029import java.util.LinkedList;
030import java.util.List;
031import java.util.Set;
032import java.util.concurrent.atomic.AtomicInteger;
033import java.util.function.BiFunction;
034import java.util.function.BinaryOperator;
035import java.util.function.Consumer;
036import java.util.function.Supplier;
037import java.util.stream.Collectors;
038import java.util.stream.Stream;
039
040import org.semanticweb.owlapi.model.IRI;
041
042import com.google.common.collect.HashMultimap;
043import com.google.common.collect.Multimap;
044import com.google.common.collect.Multimaps;
045import com.google.common.collect.Sets;
046
047import conexp.fx.core.collections.BitSetFX;
048import conexp.fx.core.collections.Collections3;
049import conexp.fx.core.dl.ELConceptDescription;
050import conexp.fx.core.dl.ELParser;
051import conexp.fx.core.dl.Signature;
052import conexp.fx.core.util.Meter;
053
054@Deprecated
055public final class ELNeighborhoodTest {
056
057  public static void main(String[] args) {
058    test19();
059  }
060
061  public static final void test1() {
062    // final ELConceptDescription C = new ELConceptDescription();
063    // C.getConceptNames().add(IRI.create("A"));
064    // // C.getConceptNames().add(IRI.create("B"));
065    // // C.getConceptNames().add(IRI.create("C"));
066    // // C.getConceptNames().add(IRI.create("D"));
067    // final ELConceptDescription C1 = new ELConceptDescription();
068    // C1.getConceptNames().add(IRI.create("A"));
069    // C.getExistentialRestrictions().add(Pair.of(IRI.create("r"), C1));
070    // final ELConceptDescription C2 = new ELConceptDescription();
071    // C2.getConceptNames().add(IRI.create("A"));
072    // C1.getExistentialRestrictions().add(Pair.of(IRI.create("r"), C2));
073    // final ELConceptDescription C3 = new ELConceptDescription();
074    // C3.getConceptNames().add(IRI.create("A"));
075    // C2.getExistentialRestrictions().add(Pair.of(IRI.create("r"), C3));
076  }
077
078  private static final void test2() {
079    // final ELConceptDescription C = ELParser.read("A AND EXISTS r . ( A AND EXISTS
080    // r . ( A AND EXISTS r . A ) )");
081    final Deque<String> sources = new LinkedList<>();
082    // sources.add("A AND B");
083    sources.add("A1 and A2 and A3 and A4 and A5");
084    for (int i = 1; i < 100; i++) {
085      // sources.add("A AND B AND EXISTS r.(" + sources.getLast() + ") AND EXISTS s.("
086      // + sources.getLast() + ")");
087      sources.add(sources.getFirst() + " and exists r.(" + sources.getLast() + ")");
088      final ELConceptDescription C = ELParser.read(sources.getLast());
089      final Set<ELConceptDescription> Us = C.upperNeighbors();
090      // System.out.println(i + " -- " + C);
091      System.out.println("C" + i);
092      System.out.println("has size " + C.size());
093      System.out.println("and squared size " + C.size() * C.size());
094      System.out
095          .println(
096              "and its upper neighbors have size "
097                  + Us.parallelStream().collect(Collectors.summingLong(ELConceptDescription::size)));
098      // System.out.println(C + " has the following upper neighbors:");
099      // Us.forEach(System.out::println);
100      System.out.println();
101    }
102  }
103
104  private static final void test3() {
105    final Meter<Long> timer = Meter.newNanoStopWatch();
106    final ELConceptDescription C = ELParser.read("exists r.(A and exists r.(A and B) and exists r.(B and C))");
107    System.out.println(C);
108    final AtomicInteger p = new AtomicInteger(0);
109    final BitSetFX ds = new BitSetFX();
110    recurse(C, 0, p::incrementAndGet, d -> {
111      synchronized (ds) {
112        ds.add(d);
113      }
114    });
115    System.out.println("branches: " + p);
116    System.out.println("quasi rank: " + ds);
117    System.out.println("computation time: " + timer.measureAndFormat());
118    timer.reset();
119    System.out.println("rank: " + C.rank());
120    System.out.println("computation time: " + timer.measureAndFormat());
121  }
122
123  private static final void
124      recurse(final ELConceptDescription C, final int d, final Supplier<Integer> pinc, final Consumer<Integer> dadd) {
125    if (C.isTop()) {
126      pinc.get();
127      dadd.accept(d);
128      return;
129    }
130    C.upperNeighborsReduced().parallelStream().forEach(D -> {
131//      D.reduce();
132      recurse(D, d + 1, pinc, dadd);
133    });
134  }
135
136  private static final void test4() {
137    final ELConceptDescription C = ELParser.read("exists r.(A and B) and exists r.(A and C) and exists r.(B and C)");
138    C.upperNeighborsReduced().forEach(System.out::println);
139  }
140
141  private static final void test5() {
142    final ELConceptDescription C = ELParser.read("exists r.(A and exists r.(A and B))");
143    C.upperNeighborsReduced().forEach(System.out::println);
144  }
145
146  private static final void test6() {
147    final ELConceptDescription C = ELParser.read("A and exists r.(A and B)");
148    C.upperNeighborsReduced().forEach(System.out::println);
149  }
150
151  private static final void test7() {
152    final Meter<Long> timer = Meter.newNanoStopWatch();
153    final ELConceptDescription C = ELParser.read("exists r.(A and exists r.(A and B) and exists r.(B and C))");
154    System.out.println(C);
155    System.out.println("rank: " + C.rank());
156    System.out.println("computation time: " + timer.measureAndFormat());
157  }
158
159  private static final void test8() {
160    final Signature sigma = new Signature(IRI.create("conexp-fx"));
161    sigma.addConceptNames("A", "B", "C", "D", "E", "F", "G", "H");
162    sigma.addRoleNames("r", "s", "t");
163//    final ELConceptDescription C = ELParser.read("A⊓B⊓E⊓F⊓∃s.(A⊓B⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D)⊓∃s.(B⊓C⊓D⊓F)");
164//    final ELConceptDescription C = ELParser.read("B⊓C⊓D⊓∃s.(A⊓B⊓C⊓D⊓E⊓F⊓∃r.(A⊓B⊓C⊓D⊓F)⊓∃r.(B⊓C⊓D⊓E⊓F)⊓∃r.(A⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D))");
165//    final ELConceptDescription C = ELParser.read("A⊓B⊓C⊓F⊓∃r.(A⊓B⊓D⊓F⊓∃r.(A⊓C)⊓∃r.(A⊓D⊓∃r.∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃r.(A⊓∃r.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.(∃r.(A⊓B⊓C⊓D⊓F)⊓∃r.(B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.(B⊓C⊓D⊓∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.(A⊓B⊓C⊓E⊓F⊓∃r.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃s.(∃r.(A⊓C)⊓∃r.(A⊓B⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃s.(B⊓C⊓E⊓F⊓∃s.(A⊓B⊓D⊓E⊓F)⊓∃s.(B⊓C))⊓∃s.(A⊓D⊓E⊓F⊓∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓D⊓F))⊓∃s.∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓F⊓∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃s.(A⊓B⊓C⊓D⊓E⊓F⊓∃r.(A⊓B⊓D⊓E⊓F)⊓∃r.(B⊓C⊓D⊓E⊓F)⊓∃r.(A⊓B⊓C⊓D⊓E)⊓∃s.(B⊓C⊓D⊓E)⊓∃s.(A⊓C⊓D⊓E⊓F))⊓∃s.(B⊓C⊓D⊓E⊓F⊓∃r.(A⊓B⊓C⊓D⊓E⊓F))⊓∃s.(A⊓B⊓C⊓D⊓E⊓F⊓∃r.(A⊓B⊓C⊓D⊓E⊓F))⊓∃s.(A⊓C⊓E⊓∃s.(A⊓B⊓C⊓D⊓E⊓F)))⊓∃r.(B⊓C)⊓∃s.(A⊓B⊓C⊓D⊓E))⊓∃r.(∃r.D⊓∃r.C⊓∃r.(∃r.(B⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.(E⊓∃r.(A⊓B⊓C⊓D⊓E⊓F)⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.C))⊓∃s.(A⊓B⊓C⊓D⊓E⊓F⊓∃s.(B⊓C⊓∃r.(A⊓B⊓C⊓D⊓E⊓F⊓∃r.⊤)⊓∃r.(A⊓B⊓C⊓D⊓E⊓F⊓∃s.(A⊓B⊓C⊓D⊓E⊓F))⊓∃r.(B⊓C⊓D⊓E⊓∃r.(A⊓B⊓C⊓D⊓E⊓F))))");
166    final ELConceptDescription C = ELConceptDescription.random(sigma, 8, 2048, 4096);
167    C.reduce();
168    System.out.println(C);
169    final Meter<Long> timer = Meter.newNanoStopWatch();
170    System.out.println("has role depth: " + C.roleDepth());
171    System.out.println("computation time: " + timer.measureAndFormat());
172    timer.reset();
173    System.out.println("has size: " + C.size());
174    System.out.println("computation time: " + timer.measureAndFormat());
175    timer.reset();
176//    System.out.println("has rank: " + C.rank());
177//    System.out.println("computation time: " + timer.measureAndFormat());
178    System.out.println("and has the following upper neighbors:");
179    timer.reset();
180    Set<ELConceptDescription> upperNeighbors = C.upperNeighbors();
181    final String upperNeighborsTime = timer.measureAndFormat();
182    final AtomicInteger i = new AtomicInteger(0);
183    upperNeighbors.forEach(D -> {
184//      System.out.println(i.incrementAndGet() + " --- " + D.rank() + " --- " + D);
185      System.out.println(i.incrementAndGet() + " --- " + D);
186    });
187    System.out.println("computation time: " + upperNeighborsTime);
188    System.out.println();
189
190    System.out.println("and has the following lower neighbors:");
191    timer.reset();
192    Set<ELConceptDescription> lowerNeighbors = C.lowerNeighbors(sigma);
193    final String lowerNeighborsTime = timer.measureAndFormat();
194    i.set(0);
195    lowerNeighbors.forEach(D -> {
196      D.reduce();
197//      System.out.println(
198//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
199//              + " --- " + D.rank() + " --- " + D);
200      System.out
201          .println(
202              i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
203                  + " --- " + C.isEquivalentTo(D) + " --- " + D);
204//      System.out.println(i.incrementAndGet() + " --- " + D);
205    });
206    System.out.println("computation time: " + lowerNeighborsTime);
207    System.out.println();
208
209    System.out.println("and has the following lower neighbors (vA):");
210    timer.reset();
211    Set<ELConceptDescription> lowerNeighborsA = C.lowerNeighborsA(sigma);
212    final String lowerNeighborsATime = timer.measureAndFormat();
213    i.set(0);
214    lowerNeighborsA.forEach(D -> {
215      D.reduce();
216//      System.out.println(
217//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
218//              + " --- " + D.rank() + " --- " + D);
219      System.out
220          .println(
221              i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
222                  + " --- " + C.isEquivalentTo(D) + " --- " + D);
223//      System.out.println(i.incrementAndGet() + " --- " + D);
224    });
225    System.out.println("computation time: " + lowerNeighborsATime);
226    System.out.println();
227
228    System.out.println("and has the following lower neighbors (vB):");
229    timer.reset();
230    Set<ELConceptDescription> lowerNeighborsB = C.lowerNeighborsB(sigma);
231    final String lowerNeighborsBTime = timer.measureAndFormat();
232    i.set(0);
233    lowerNeighborsB.forEach(D -> {
234      D.reduce();
235//      System.out.println(
236//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
237//              + " --- " + D.rank() + " --- " + D);
238      System.out
239          .println(
240              i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
241                  + " --- " + C.isEquivalentTo(D) + " --- " + D);
242//      System.out.println(i.incrementAndGet() + " --- " + D);
243    });
244    System.out.println("computation time: " + lowerNeighborsBTime);
245    System.out.println();
246
247//    System.out.println("and has the following lower neighbors (v14):");
248//    timer.reset();
249//    Set<ELConceptDescription> lowerNeighbors14 = C.lowerNeighbors14(sigma);
250//    final String lowerNeighbors14Time = timer.measureAndFormat();
251//    i.set(0);
252//    lowerNeighbors14.forEach(D -> {
253//      D.reduce();
254////      System.out.println(
255////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
256////              + " --- " + D.rank() + " --- " + D);
257//      System.out.println(
258//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
259//              + " --- " + D);
260////      System.out.println(i.incrementAndGet() + " --- " + D);
261//    });
262//    System.out.println("computation time: " + lowerNeighbors14Time);
263//    System.out.println();
264//
265//    System.out.println("and has the following lower neighbors (v13):");
266//    timer.reset();
267//    Set<ELConceptDescription> lowerNeighbors13 = C.lowerNeighbors13(sigma);
268//    final String lowerNeighbors13Time = timer.measureAndFormat();
269//    i.set(0);
270//    lowerNeighbors13.forEach(D -> {
271//      D.reduce();
272////      System.out.println(
273////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
274////              + " --- " + D.rank() + " --- " + D);
275//      System.out.println(
276//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
277//              + " --- " + D);
278////      System.out.println(i.incrementAndGet() + " --- " + D);
279//    });
280//    System.out.println("computation time: " + lowerNeighbors13Time);
281//    System.out.println();
282//
283//    System.out.println("and has the following lower neighbors (v12):");
284//    timer.reset();
285//    Set<ELConceptDescription> lowerNeighbors12 = C.lowerNeighbors12(sigma);
286//    final String lowerNeighbors12Time = timer.measureAndFormat();
287//    i.set(0);
288//    lowerNeighbors12.forEach(D -> {
289//      D.reduce();
290////      System.out.println(
291////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
292////              + " --- " + D.rank() + " --- " + D);
293//      System.out.println(
294//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
295//              + " --- " + D);
296////      System.out.println(i.incrementAndGet() + " --- " + D);
297//    });
298//    System.out.println("computation time: " + lowerNeighbors12Time);
299//    System.out.println();
300//
301//    System.out.println("and has the following lower neighbors (v11):");
302//    timer.reset();
303//    Set<ELConceptDescription> lowerNeighbors11 = C.lowerNeighbors11(sigma);
304//    final String lowerNeighbors11Time = timer.measureAndFormat();
305//    i.set(0);
306//    lowerNeighbors11.forEach(D -> {
307//      D.reduce();
308////      System.out.println(
309////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
310////              + " --- " + D.rank() + " --- " + D);
311//      System.out.println(
312//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
313//              + " --- " + D);
314////      System.out.println(i.incrementAndGet() + " --- " + D);
315//    });
316//    System.out.println("computation time: " + lowerNeighbors11Time);
317//    System.out.println();
318//
319//    System.out.println("and has the following lower neighbors (v10):");
320//    timer.reset();
321//    Set<ELConceptDescription> lowerNeighbors10 = C.lowerNeighbors10(sigma);
322//    final String lowerNeighbors10Time = timer.measureAndFormat();
323//    i.set(0);
324//    lowerNeighbors10.forEach(D -> {
325//      D.reduce();
326////      System.out.println(
327////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
328////              + " --- " + D.rank() + " --- " + D);
329//      System.out.println(
330//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
331//              + " --- " + D);
332////      System.out.println(i.incrementAndGet() + " --- " + D);
333//    });
334//    System.out.println("computation time: " + lowerNeighbors10Time);
335//    System.out.println();
336//
337//    System.out.println("and has the following lower neighbors (v9):");
338//    timer.reset();
339//    Set<ELConceptDescription> lowerNeighbors9 = C.lowerNeighbors9(sigma);
340//    final String lowerNeighbors9Time = timer.measureAndFormat();
341//    i.set(0);
342//    lowerNeighbors9.forEach(D -> {
343//      D.reduce();
344////      System.out.println(
345////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
346////              + " --- " + D.rank() + " --- " + D);
347//      System.out.println(
348//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
349//              + " --- " + D);
350////      System.out.println(i.incrementAndGet() + " --- " + D);
351//    });
352//    System.out.println("computation time: " + lowerNeighbors9Time);
353//    System.out.println();
354//
355//    System.out.println("and has the following lower neighbors (v8):");
356//    timer.reset();
357//    Set<ELConceptDescription> lowerNeighbors8 = C.lowerNeighbors8(sigma);
358//    final String lowerNeighbors8Time = timer.measureAndFormat();
359//    i.set(0);
360//    lowerNeighbors8.forEach(D -> {
361//      D.reduce();
362////      System.out.println(
363////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
364////              + " --- " + D.rank() + " --- " + D);
365//      System.out.println(
366//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
367//              + " --- " + D);
368////      System.out.println(i.incrementAndGet() + " --- " + D);
369//    });
370//    System.out.println("computation time: " + lowerNeighbors8Time);
371//    System.out.println();
372//
373////    System.out.println("and has the following lower neighbors:");
374////    timer.reset();
375////    Set<ELConceptDescription> lowerNeighbors = C.lowerNeighborsReduced(sigma);
376////    final String lowerNeighborsTime = timer.measureAndFormat();
377////    i.set(0);
378////    lowerNeighbors.forEach(D -> {
379//////      final ELConceptDescription rE = D.clone();
380//////      rE.getConceptNames().removeAll(C.getConceptNames());
381//////      rE.getExistentialRestrictions().entries().removeAll(C.getExistentialRestrictions().entries());
382////      D.reduce();
383//////      System.out.println(
384//////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
385//////              + " --- " + D.rank() + " --- " + D);
386////      System.out.println(
387////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
388////              + " --- " + D);
389//////      System.out.println("   new conjunct: " + rE);
390//////      System.out.println(i.incrementAndGet() + " --- " + D);
391////    });
392////    System.out.println("computation time: " + lowerNeighborsTime);
393////    System.out.println("and has the following lower neighbors (v2):");
394////    timer.reset();
395////    Set<ELConceptDescription> lowerNeighbors2 = C.lowerNeighbors2(sigma);
396////    final String lowerNeighbors2Time = timer.measureAndFormat();
397////    i.set(0);
398////    lowerNeighbors2.forEach(D -> {
399//////      D.reduce();
400//////      System.out.println(
401//////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
402//////              + " --- " + D.rank() + " --- " + D);
403////      System.out.println(i.incrementAndGet() + " --- " + D);
404////    });
405////    System.out.println("computation time: " + lowerNeighbors2Time);
406////    System.out.println("and has the following lower neighbors (v3):");
407////    timer.reset();
408////    Set<ELConceptDescription> lowerNeighbors3 = C.lowerNeighbors3(sigma);
409////    final String lowerNeighbors3Time = timer.measureAndFormat();
410////    i.set(0);
411////    lowerNeighbors3.forEach(D -> {
412////      D.reduce();
413////      System.out.println(
414////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
415////              + " --- " + D.rank() + " --- " + D);
416//////      System.out.println(i.incrementAndGet() + " --- " + D);
417////    });
418////    System.out.println("computation time: " + lowerNeighbors3Time);
419////    System.out.println();
420//    System.out.println("and has the following lower neighbors (v4):");
421//    timer.reset();
422//    Set<ELConceptDescription> lowerNeighbors4 = C.lowerNeighbors4(sigma);
423//    final String lowerNeighbors4Time = timer.measureAndFormat();
424//    i.set(0);
425//    lowerNeighbors4.forEach(D -> {
426//      D.reduce();
427////      System.out.println(
428////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
429////              + " --- " + D.rank() + " --- " + D);
430//      System.out.println(
431//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
432//              + " --- " + D);
433////      System.out.println(i.incrementAndGet() + " --- " + D);
434//    });
435//    System.out.println("computation time: " + lowerNeighbors4Time);
436//    System.out.println();
437//    System.out.println("and has the following lower neighbors (v5):");
438//    timer.reset();
439//    Set<ELConceptDescription> lowerNeighbors5 = C.lowerNeighbors5(sigma);
440//    final String lowerNeighbors5Time = timer.measureAndFormat();
441//    i.set(0);
442//    lowerNeighbors5.forEach(D -> {
443//      D.reduce();
444////      System.out.println(
445////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
446////              + " --- " + D.rank() + " --- " + D);
447//      System.out.println(
448//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
449//              + " --- " + D);
450////      System.out.println(i.incrementAndGet() + " --- " + D);
451//    });
452//    System.out.println("computation time: " + lowerNeighbors5Time);
453//    System.out.println();
454//    System.out.println("and has the following lower neighbors (v6):");
455//    timer.reset();
456//    Set<ELConceptDescription> lowerNeighbors6 = C.lowerNeighbors6(sigma);
457//    final String lowerNeighbors6Time = timer.measureAndFormat();
458//    i.set(0);
459//    lowerNeighbors6.forEach(D -> {
460//      D.reduce();
461////      System.out.println(
462////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
463////              + " --- " + D.rank() + " --- " + D);
464//      System.out.println(
465//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
466//              + " --- " + D);
467////      System.out.println(i.incrementAndGet() + " --- " + D);
468//    });
469//    System.out.println("computation time: " + lowerNeighbors6Time);
470//    System.out.println();
471//    System.out.println("and has the following lower neighbors (v7):");
472//    timer.reset();
473//    Set<ELConceptDescription> lowerNeighbors7 = C.lowerNeighbors7(sigma);
474//    final String lowerNeighbors7Time = timer.measureAndFormat();
475//    i.set(0);
476//    lowerNeighbors7.forEach(D -> {
477//      D.reduce();
478////      System.out.println(
479////          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
480////              + " --- " + D.rank() + " --- " + D);
481//      System.out.println(
482//          i.incrementAndGet() + " --- " + D.upperNeighborsReduced().parallelStream().anyMatch(C::isEquivalentTo)
483//              + " --- " + D);
484////      System.out.println(i.incrementAndGet() + " --- " + D);
485//    });
486//    System.out.println("computation time: " + lowerNeighbors7Time);
487//    System.out.println();
488    final int size = Collections3.quotient(lowerNeighbors, ELConceptDescription.equivalence()).size();
489    final int sizeA = Collections3.quotient(lowerNeighborsA, ELConceptDescription.equivalence()).size();
490    final int sizeB = Collections3.quotient(lowerNeighborsB, ELConceptDescription.equivalence()).size();
491////    final int size1 = Collections3.quotient(lowerNeighbors, ELConceptDescription.equivalence()).size();
492//    final int size4 = Collections3.quotient(lowerNeighbors4, ELConceptDescription.equivalence()).size();
493//    final int size5 = Collections3.quotient(lowerNeighbors5, ELConceptDescription.equivalence()).size();
494////    final int size6 = Collections3.quotient(lowerNeighbors6, ELConceptDescription.equivalence()).size();
495////    final int size7 = Collections3.quotient(lowerNeighbors7, ELConceptDescription.equivalence()).size();
496//    final int size8 = Collections3.quotient(lowerNeighbors8, ELConceptDescription.equivalence()).size();
497//    final int size9 = Collections3.quotient(lowerNeighbors9, ELConceptDescription.equivalence()).size();
498//    final int size10 = Collections3.quotient(lowerNeighbors10, ELConceptDescription.equivalence()).size();
499//    final int size11 = Collections3.quotient(lowerNeighbors11, ELConceptDescription.equivalence()).size();
500//    final int size12 = Collections3.quotient(lowerNeighbors12, ELConceptDescription.equivalence()).size();
501//    final int size13 = Collections3.quotient(lowerNeighbors13, ELConceptDescription.equivalence()).size();
502//    final int size14 = Collections3.quotient(lowerNeighbors14, ELConceptDescription.equivalence()).size();
503//    System.out.println("1=2   " + equalsEquivalent(lowerNeighbors, lowerNeighbors2));
504//    System.out.println("1=3   " + equalsEquivalent(lowerNeighbors, lowerNeighbors3));
505    System.out.println("time   = " + lowerNeighborsTime);
506    System.out.println("timeA  = " + lowerNeighborsATime);
507    System.out.println("timeB  = " + lowerNeighborsBTime);
508////    System.out.println("time1  = " + lowerNeighborsTime);
509//    System.out.println("time4  = " + lowerNeighbors4Time);
510//    System.out.println("time5  = " + lowerNeighbors5Time);
511////    System.out.println("time6  = " + lowerNeighbors6Time);
512////    System.out.println("time7  = " + lowerNeighbors7Time);
513//    System.out.println("time8  = " + lowerNeighbors8Time);
514//    System.out.println("time9  = " + lowerNeighbors9Time);
515//    System.out.println("time10 = " + lowerNeighbors10Time);
516//    System.out.println("time11 = " + lowerNeighbors11Time);
517//    System.out.println("time12 = " + lowerNeighbors12Time);
518//    System.out.println("time13 = " + lowerNeighbors13Time);
519//    System.out.println("time14 = " + lowerNeighbors14Time);
520    System.out.println("size   = " + size);
521    System.out.println("sizeA  = " + sizeA);
522    System.out.println("sizeB  = " + sizeB);
523////    System.out.println("size1  = " + size1);
524//    System.out.println("size4  = " + size4);
525//    System.out.println("size5  = " + size5);
526////    System.out.println("size6  = " + size6);
527////    System.out.println("size7  = " + size7);
528//    System.out.println("size8  = " + size8);
529//    System.out.println("size9  = " + size9);
530//    System.out.println("size10 = " + size10);
531//    System.out.println("size11 = " + size11);
532//    System.out.println("size12 = " + size12);
533//    System.out.println("size13 = " + size13);
534//    System.out.println("size14 = " + size14);
535    System.out.println("A<!    " + containsEquivalent(lowerNeighborsA, lowerNeighbors));
536    System.out.println("A>!    " + containsEquivalent(lowerNeighbors, lowerNeighborsA));
537    System.out.println("A=!    " + equalsEquivalent(lowerNeighborsA, lowerNeighbors));
538    System.out.println("B<!    " + containsEquivalent(lowerNeighborsB, lowerNeighbors));
539    System.out.println("B>!    " + containsEquivalent(lowerNeighbors, lowerNeighborsB));
540    System.out.println("B=!    " + equalsEquivalent(lowerNeighborsB, lowerNeighbors));
541//    System.out.println("4<!    " + containsEquivalent(lowerNeighbors4, lowerNeighbors));
542//    System.out.println("4>!    " + containsEquivalent(lowerNeighbors, lowerNeighbors4));
543//    System.out.println("4=!    " + equalsEquivalent(lowerNeighbors4, lowerNeighbors));
544////    System.out.println("1<4    " + containsEquivalent(lowerNeighbors, lowerNeighbors4));
545////    System.out.println("4<1    " + containsEquivalent(lowerNeighbors4, lowerNeighbors));
546////    System.out.println("1=4    " + equalsEquivalent(lowerNeighbors, lowerNeighbors4));
547////    System.out.println("1<5    " + containsEquivalent(lowerNeighbors, lowerNeighbors5));
548////    System.out.println("5<1    " + containsEquivalent(lowerNeighbors5, lowerNeighbors));
549////    System.out.println("1=5    " + equalsEquivalent(lowerNeighbors, lowerNeighbors5));
550//    System.out.println("4<5    " + containsEquivalent(lowerNeighbors4, lowerNeighbors5));
551//    System.out.println("4>5    " + containsEquivalent(lowerNeighbors5, lowerNeighbors4));
552//    System.out.println("4=5    " + equalsEquivalent(lowerNeighbors4, lowerNeighbors5));
553////    System.out.println("5<6    " + containsEquivalent(lowerNeighbors5, lowerNeighbors6));
554////    System.out.println("5>6    " + containsEquivalent(lowerNeighbors6, lowerNeighbors5));
555////    System.out.println("5=6    " + equalsEquivalent(lowerNeighbors5, lowerNeighbors6));
556////    System.out.println("5<7    " + containsEquivalent(lowerNeighbors5, lowerNeighbors7));
557////    System.out.println("5>7    " + containsEquivalent(lowerNeighbors7, lowerNeighbors5));
558////    System.out.println("5=7    " + equalsEquivalent(lowerNeighbors5, lowerNeighbors7));
559//    System.out.println("5<8    " + containsEquivalent(lowerNeighbors5, lowerNeighbors8));
560//    System.out.println("5>8    " + containsEquivalent(lowerNeighbors8, lowerNeighbors5));
561//    System.out.println("5=8    " + equalsEquivalent(lowerNeighbors5, lowerNeighbors8));
562//    System.out.println("5<9    " + containsEquivalent(lowerNeighbors5, lowerNeighbors9));
563//    System.out.println("5>9    " + containsEquivalent(lowerNeighbors9, lowerNeighbors5));
564//    System.out.println("5=9    " + equalsEquivalent(lowerNeighbors5, lowerNeighbors9));
565//    System.out.println("5<10   " + containsEquivalent(lowerNeighbors5, lowerNeighbors10));
566//    System.out.println("5>10   " + containsEquivalent(lowerNeighbors10, lowerNeighbors5));
567//    System.out.println("5=10   " + equalsEquivalent(lowerNeighbors5, lowerNeighbors10));
568//    System.out.println("5<11   " + containsEquivalent(lowerNeighbors5, lowerNeighbors11));
569//    System.out.println("5>11   " + containsEquivalent(lowerNeighbors11, lowerNeighbors5));
570//    System.out.println("5=11   " + equalsEquivalent(lowerNeighbors5, lowerNeighbors11));
571//    System.out.println("5<12   " + containsEquivalent(lowerNeighbors5, lowerNeighbors12));
572//    System.out.println("5>12   " + containsEquivalent(lowerNeighbors12, lowerNeighbors5));
573//    System.out.println("5=12   " + equalsEquivalent(lowerNeighbors5, lowerNeighbors12));
574//    System.out.println("5<13   " + containsEquivalent(lowerNeighbors5, lowerNeighbors13));
575//    System.out.println("5>13   " + containsEquivalent(lowerNeighbors13, lowerNeighbors5));
576//    System.out.println("5=13   " + equalsEquivalent(lowerNeighbors5, lowerNeighbors13));
577//    System.out.println("5<14   " + containsEquivalent(lowerNeighbors5, lowerNeighbors14));
578//    System.out.println("5>14   " + containsEquivalent(lowerNeighbors14, lowerNeighbors5));
579//    System.out.println("5=14   " + equalsEquivalent(lowerNeighbors5, lowerNeighbors14));
580    System.out.println();
581//    System.out.println(C + " has the following lower neighbors, that method v6 does not compute:");
582//    Collections3
583//        .representatives(lowerNeighbors4, ELConceptDescription.equivalence())
584//        .parallelStream()
585//        .filter(L -> lowerNeighbors6.parallelStream().noneMatch(L::isEquivalentTo))
586//        .forEach(System.out::println);
587//    System.out.println();
588//    System.out.println(C + " has the following lower neighbors, that method v7 does not compute:");
589//    Collections3
590//        .representatives(lowerNeighbors4, ELConceptDescription.equivalence())
591//        .parallelStream()
592//        .filter(L -> lowerNeighbors7.parallelStream().noneMatch(L::isEquivalentTo))
593//        .forEach(System.out::println);
594//    System.out.println();
595//    System.out.println(C + " has the following lower neighbors, that method v11 does not compute:");
596//    Collections3
597//        .representatives(lowerNeighbors5, ELConceptDescription.equivalence())
598//        .parallelStream()
599//        .filter(L -> lowerNeighbors11.parallelStream().noneMatch(L::isEquivalentTo))
600//        .forEach(D -> {
601//          // System.out.println(D);
602//          final ELConceptDescription rE = D.clone();
603//          rE.getConceptNames().removeAll(C.getConceptNames());
604//          rE.getExistentialRestrictions().entries().removeAll(C.getExistentialRestrictions().entries());
605//          System.out.println("   new conjunct: " + rE);
606//        });
607//    System.out.println();
608//    System.out.println(C + " has the following lower neighbors, that method v12 does not compute:");
609//    Collections3
610//        .representatives(lowerNeighbors5, ELConceptDescription.equivalence())
611//        .parallelStream()
612//        .filter(L -> lowerNeighbors12.parallelStream().noneMatch(L::isEquivalentTo))
613//        .forEach(D -> {
614//          // System.out.println(D);
615//          final ELConceptDescription rE = D.clone();
616//          rE.getConceptNames().removeAll(C.getConceptNames());
617//          rE.getExistentialRestrictions().entries().removeAll(C.getExistentialRestrictions().entries());
618//          System.out.println("   new conjunct: " + rE);
619//        });
620//    System.out.println();
621//    System.out.println(C + " has the following lower neighbors, that method v13 does not compute:");
622//    Collections3
623//        .representatives(lowerNeighbors5, ELConceptDescription.equivalence())
624//        .parallelStream()
625//        .filter(L -> lowerNeighbors13.parallelStream().noneMatch(L::isEquivalentTo))
626//        .forEach(D -> {
627//          // System.out.println(D);
628//          final ELConceptDescription rE = D.clone();
629//          rE.getConceptNames().removeAll(C.getConceptNames());
630//          rE.getExistentialRestrictions().entries().removeAll(C.getExistentialRestrictions().entries());
631//          System.out.println("   new conjunct: " + rE);
632//        });
633//    System.out.println("2=3   " + equalsEquivalent(lowerNeighbors2, lowerNeighbors3));
634  }
635
636  private static final boolean
637      containsEquivalent(final Set<ELConceptDescription> Cs, final Set<ELConceptDescription> Ds) {
638    return Cs.parallelStream().allMatch(C -> Ds.parallelStream().anyMatch(C::isEquivalentTo));
639  }
640
641  private static final boolean
642      equalsEquivalent(final Set<ELConceptDescription> Cs, final Set<ELConceptDescription> Ds) {
643    return Stream
644        .<Supplier<Boolean>> of(() -> containsEquivalent(Cs, Ds), () -> containsEquivalent(Ds, Cs))
645        .parallel()
646        .allMatch(Supplier::get);
647  }
648
649  private static final void test9() {
650    final ELConceptDescription C = ELParser.read("A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3))"
651//            "A1⊓A2⊓A3⊓∃s.(A1⊓∃r.A3⊓∃s.A3⊓∃r.(A2⊓∃s.⊤))⊓∃s.(∃r.⊤⊓∃s.(A2⊓∃r.A3)⊓∃s.∃r.A4)⊓∃r.(A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3))⊓∃s.(A3⊓A4)⊓∃s.A2"
652//            "A1⊓A2⊓A3⊓∃s.(A1⊓∃r.A3⊓∃s.A3⊓∃r.(A2⊓∃s.⊤))⊓∃s.(∃r.⊤⊓∃s.(A2⊓∃r.A3)⊓∃s.∃r.A4)⊓∃s.∃r.(A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3))⊓∃s.(A3⊓A4)⊓∃s.A2"
653//        "A1⊓A2⊓A3⊓∃s.(A1⊓∃r.A3⊓∃s.A3⊓∃r.(A2⊓∃s.⊤))⊓∃s.(∃r.⊤⊓∃s.(A2⊓∃r.A3)⊓∃s.∃r.A4)⊓∃r.(A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3))⊓∃s.(A3⊓A4)⊓∃s.A2 and exists r.(A1⊓A2⊓A3⊓∃s.(A1⊓∃r.A3⊓∃s.A3⊓∃r.(A2⊓∃s.⊤))⊓∃s.(∃r.⊤⊓∃s.(A2⊓∃r.A3)⊓∃s.∃r.A4)⊓∃r.(A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3))⊓∃s.(A3⊓A4)⊓∃s.A2)"
654    );
655    C.reduce();
656    System.out.println(C);
657    final Meter<Long> timer = Meter.newNanoStopWatch();
658    for (int i = 0; i < 3; i++) {
659      timer.reset();
660      System.out.println("rank: " + C.unreducedRank());
661      System.out.println("computation time: " + timer.measureAndFormat());
662      timer.reset();
663      System.out.println("rank2: " + C.unreducedRank2());
664      System.out.println("computation time: " + timer.measureAndFormat());
665      timer.reset();
666      System.out.println("rank3: " + C.rank3());
667      System.out.println("computation time: " + timer.measureAndFormat());
668      timer.reset();
669      System.out.println("rank4: " + C.unreducedRank4());
670      System.out.println("computation time: " + timer.measureAndFormat());
671    }
672  }
673
674  private static final void test10() {
675    final Meter<Long> timer = Meter.newNanoStopWatch();
676    String source = "(A⊓B⊓C)";
677    for (int i = 0; i < 10; i++) {
678      source = "∃r." + source;
679      final ELConceptDescription C = ELParser.read(source);
680      System.out.println(C);
681      timer.reset();
682      System.out.println("rank1: " + C.rank());
683      System.out.println("computation time: " + timer.measureAndFormat());
684//      timer.reset();
685//      System.out.println("rank3: " + C.rank3());
686//      System.out.println("computation time: " + timer.measureAndFormat());
687      timer.reset();
688      System.out.println("rank2: " + C.rank2());
689      System.out.println("computation time: " + timer.measureAndFormat());
690      System.out.println();
691    }
692  }
693
694  private static final void test11() {
695    final ELConceptDescription C = ELParser.read("A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓A3⊓∃r.(A1⊓A2))");
696    final ELConceptDescription D = ELParser.read("A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓∃r.(A1⊓A2⊓A3)⊓∃r.∃s.(A1 and A2 AND A3))");
697    C.reduce();
698    D.reduce();
699    System.out.println(C);
700    System.out.println(D);
701    final Meter<Long> timer = Meter.newNanoStopWatch();
702    for (int i = 0; i < 3; i++) {
703      timer.reset();
704      System.out.println("distance: " + C.distanceTo(D));
705      System.out.println("computation time: " + timer.measureAndFormat());
706      timer.reset();
707      System.out.println("distance2: " + C.distanceTo2(D));
708      System.out.println("computation time: " + timer.measureAndFormat());
709    }
710  }
711
712  private static final void test12() {
713    final Signature sigma = new Signature(IRI.create("foo"));
714    sigma.addConceptNames("A1", "A2", "A3", "A4");
715    sigma.addRoleNames("r", "s");
716    final ELConceptDescription C = ELParser.read("A1⊓A2⊓A3⊓∃r.(A1⊓A2⊓∃r.(A1⊓A2⊓A3)⊓∃s.(A1 and ∃r.A3))");
717    C.reduce();
718    final int radius = 3;
719    System.out.println(C);
720    System.out.println("radius: " + radius);
721    final Meter<Long> timer = Meter.newNanoStopWatch();
722    for (int i = 0; i < 3; i++) {
723      timer.reset();
724      final Set<ELConceptDescription> neighborhood = C.neighborhood(radius, sigma);
725      final String ctime = timer.measureAndFormat();
726      System.out.println(neighborhood.size() + " neighbors:");
727      neighborhood.forEach(D -> System.out.println(D));
728//      neighborhood.forEach(D -> System.out.println(D.rank() + "   " + D));
729      System.out.println("computation time: " + ctime);
730    }
731  }
732
733  private static final void test13() {
734    final int n = 3;
735    final IRI r = IRI.create("r");
736    final List<ELConceptDescription> atoms = new LinkedList<>();
737    for (int i = 1; i < n + 1; i++) {
738      atoms.add(ELConceptDescription.conceptName(IRI.create("A" + i)));
739    }
740    ELConceptDescription C = ELConceptDescription.conjunction(atoms);
741    int rd = 0;
742    long rank = C.rank();
743    while (true) {
744//      final long lower = 1 + rank;
745//      long upper = 1;
746//      for (long i = 1; i < rank; i++) {
747//        long fac = 1;
748//        for (long j = 0; j < i - 2; j++)
749//          fac *= rank - j;
750//        upper += fac;
751//      }
752      C = ELConceptDescription.conjunction(C, ELConceptDescription.existentialRestriction(r, C)).reduce();
753      rd++;
754      rank = C.rank();
755      System.out.println("role depth: " + rd + "    " + "rank: " + rank);
756      System.out.println(C);
757//      System.out.println("lower bound: " + lower);
758//      System.out.println("upper bound: " + upper);
759      System.out.println();
760    }
761  }
762
763  private static final void test14() {
764    final Multimap<Integer, String> foo = Multimaps.synchronizedSetMultimap(HashMultimap.create());
765    foo.put(1, "A");
766    foo.put(1, "B");
767    foo.put(2, "X");
768    foo.put(2, "Y");
769
770    final Set<Set<String>> identity = new HashSet<>();
771    identity.add(new HashSet<>());
772    final BiFunction<Set<Set<String>>, Collection<String>, Set<Set<String>>> accumulator = (X, Y) -> {
773      System.out.println("accumulator where X=" + X + " and Y=" + Y);
774      return X.parallelStream().flatMap(x -> Y.parallelStream().map(y -> {
775        System.out.println("accumulating " + x + " and " + y);
776        final Set<String> xy = Sets.newHashSet(x);
777        xy.add(y);
778        return xy;
779      })).collect(Collectors.toSet());
780    };
781    final BinaryOperator<Set<Set<String>>> combiner = (X, Y) -> {
782      System.out.println("combiner where X=" + X + " and Y=" + Y);
783      return X.parallelStream().flatMap(x -> Y.parallelStream().map(y -> {
784        System.out.println("combining " + x + " and " + y);
785        final Set<String> xy = Sets.newHashSet(x);
786        xy.addAll(y);
787        return xy;
788      })).collect(Collectors.toSet());
789    };
790    final Set<Set<String>> cartesianProduct =
791        foo.keySet().parallelStream().map(foo::get).reduce(identity, accumulator, combiner);
792    System.out.println(cartesianProduct);
793  }
794
795  private static final void test15() {
796    for (int n = 1; n <= 16; n++) {
797      final Signature Σ = new Signature(IRI.create("conexp-fx"));
798      for (int i = 1; i <= n; i++)
799        Σ.addConceptNames("A" + i, "B" + i);
800      Σ.addRoleNames("r");
801      final ELConceptDescription C = new ELConceptDescription();
802      for (int i = 1; i <= n; i++) {
803        final ELConceptDescription D = new ELConceptDescription();
804        for (int j = 1; j <= n; j++)
805          if (i != j) {
806            D.getConceptNames().add(IRI.create("A" + j));
807            D.getConceptNames().add(IRI.create("B" + j));
808          }
809        C.getExistentialRestrictions().put(IRI.create("r"), D);
810      }
811      final int size = C.size();
812      final Set<ELConceptDescription> lowerNeighbors = C.lowerNeighbors(Σ);
813      System.out
814          .println(
815              "n = " + n + "     sqrt(size) = " + Math.sqrt(size) / 2d + "     log(number of lower neighbors) = "
816                  + Math.log(lowerNeighbors.size()) / Math.log(2d));
817    }
818  }
819
820  private static final void test16() {
821    for (int n = 1; n <= 16; n++) {
822      final Signature Σ = new Signature(IRI.create("conexp-fx"));
823      Σ.addConceptNames("A", "B", "C", "D");
824      Σ.addRoleNames("r", "s");
825      final IRI r = IRI.create("r");
826      ELConceptDescription X, Y;
827      for (X = ELParser.read("A⊓B"); X.roleDepth() < n; X = X.exists(r)) {}
828      for (Y = ELParser.read("C⊓D"); Y.roleDepth() < n; Y = Y.exists(r)) {}
829      final ELConceptDescription C = X.and(Y);
830      System.out.println("    C = " + C);
831      System.out.println("rd(C) = " + n);
832      System.out.println("||C|| = " + C.size());
833      final Integer max =
834          C.lowerNeighbors(Σ).parallelStream().map(ELConceptDescription::size).max(Integer::compare).orElse(-1);
835      System.out.println("||D|| = " + max + " for some D≺C");
836      System.out.println();
837    }
838  }
839
840  private static final void test17() {
841    for (int n = 1; n <= 16; n++) {
842      final Signature Σ = new Signature(IRI.create("conexp-fx"));
843      for (int i = 1; i <= n; i++)
844        Σ.addConceptNames("A" + i);
845      Σ.addRoleNames("r");
846      final IRI r = IRI.create("r");
847      ELConceptDescription C = new ELConceptDescription();
848      for (int i = 1; i <= n; i++) {
849        C = C.and(ELParser.read("A" + i).exists(r));
850      }
851      System.out.println("    C = " + C);
852      System.out.println("rd(C) = " + n);
853      System.out.println("||C|| = " + C.size());
854      final Integer max =
855          C.lowerNeighbors(Σ).parallelStream().map(ELConceptDescription::size).max(Integer::compare).orElse(-1);
856      System.out.println("||D|| = " + max + " for some D≺C");
857      System.out.println();
858    }
859  }
860
861  private static final void test18() {
862    final Signature Σ = new Signature(IRI.create("conexp-fx"));
863    Σ.addConceptNames("A", "B", "C");
864    Σ.addRoleNames("r");
865    for (int m = 1; m < 16; m++) {
866      ELConceptDescription X = new ELConceptDescription();
867      X.getConceptNames().add(IRI.create("A"));
868      X.getConceptNames().add(IRI.create("B"));
869      X.getConceptNames().add(IRI.create("C"));
870      System.out.println("  m   = " + m);
871      for (int n = 1; n <= m; n++) {
872        X = X.exists(IRI.create("r"));
873//        final int rank = X.rank();
874//        System.out.println("role depth = " + n);
875//        System.out.println("      rank = " + rank);
876//        System.out.println();
877      }
878      System.out.println("  X   = " + X);
879      System.out.println("||X|| = " + X.size2());
880      System.out.println(" |X|  = " + X.rank());
881      for (int n = 0; n < 256; n++) {
882////        System.out.println("n = " + n);
883//        System.out.println(X);
884        final Set<ELConceptDescription> upperNeighbors = X.upperNeighborsReduced();
885//        System.out.println("has " + upperNeighbors.size() + " upper neighbors");
886//        System.out.println();
887        if (upperNeighbors.size() > 1)
888          break;
889        X = upperNeighbors.iterator().next();
890      }
891      for (ELConceptDescription Y : X.topLevelConjuncts()) {
892        System.out.println("  Y   = " + Y);
893        System.out.println("||Y|| = " + Y.size2());
894        System.out.println(" |Y|  = " + Y.rank());
895        break;
896      }
897      System.out.println();
898    }
899  }
900
901  private static final void test19() {
902    final Meter<Long> meter = Meter.newNanoStopWatch();
903    for (int n = 3; n < 5; n++) {
904      for (int k = 0; k < 6; k++) {
905//        if ((k == 4 || k == 5) && n == 2) {
906//          System.out.println("k=" + k + " n=" + n + " skipped");
907//          continue;
908//        }
909        ELConceptDescription C = buildUglyELConceptDescription(k, n);
910        System.out.println("k=" + k + " n=" + n + " C=" + C);
911        try {
912          meter.reset();
913          final int rank = C.rank();
914          System.out.println("|C|₁=" + rank + " in " + meter.measureAndFormat());
915        } catch (Exception __) {
916          System.out.println("|C|₁=? in " + meter.measureAndFormat());
917        }
918        try {
919          meter.reset();
920          final int rank2 = C.rank2();
921          System.out.println("|C|₂=" + rank2 + " in " + meter.measureAndFormat());
922        } catch (Exception __) {
923          System.out.println("|C|₂=? in " + meter.measureAndFormat());
924        }
925//        try {
926//          meter.reset();
927//          final int rank3 = C.rank3();
928//          System.out.println("|C|₃=" + rank3 + " in " + meter.measureAndFormat());
929//        } catch (Exception __) {
930//          System.out.println("|C|₃=? in " + meter.measureAndFormat());
931//        }
932//        try {
933//          meter.reset();
934//          final int rank4 = C.rank4();
935//          System.out.println("|C|₄=" + rank4 + " in " + meter.measureAndFormat());
936//        } catch (Exception __) {
937//          System.out.println("|C|₄=? in " + meter.measureAndFormat());
938//        }
939        try {
940          meter.reset();
941          final long rank5 = C.rank5();
942          System.out.println("|C|₅=" + rank5 + " in " + meter.measureAndFormat());
943        } catch (Exception __) {
944          System.out.println("|C|₅=? in " + meter.measureAndFormat());
945        }
946      }
947      System.out.println("--------------------------------------------------------------------------------");
948    }
949  }
950
951  private static final ELConceptDescription buildUglyELConceptDescription(final int k, final int n) {
952    ELConceptDescription C = ELConceptDescription.top();
953    for (int i = 1; i <= k; i++)
954      C = C.and(ELConceptDescription.conceptName(IRI.create("A" + i)));
955    for (int j = 0; j < n; j++) {
956      C = C.exists(IRI.create("r"));
957    }
958    return C;
959  }
960
961}