Example #1
0
 // Caller must trim after; but note of trim needed is recorded in the vector
 public void remove(DMIElem e) {
   int i = itsConceptSet.indexOf(e);
   if (i >= 0) {
     itsGraph.itsCacheBuilder.Remove(e);
     itsConceptSet.clear(i);
   }
 }
Example #2
0
 private void step(ISet<DMIElem> mSet, ISet<DMIElem> outLinks) {
   int cnt = mSet.size();
   for (int i = 0; i < cnt; i++) {
     DMIElem m = mSet.get(i);
     step(m, null, outLinks);
   }
 }
Example #3
0
 private void classifyConcept(DMIElem m, ISet<DMIElem> outNodes, ISet<DMIElem> outLinks) {
   if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0)
     Tracing.gTraceFile.println("adding: " + m.itsIndex);
   setVisited(m);
   if (m.isStatement()) outLinks.add(m);
   else outNodes.add(m);
 }
Example #4
0
  /*
   * pre: set != null, text != null
   * Method to add all words in text to the given set. Words are delimited by
   * white space.
   * This version for CS314 sets.
   */
  private static void processTextCS314Sets(ISet<String> set, String text) {
    Stopwatch s = new Stopwatch();
    Scanner sc = new Scanner(text);
    int totalWords = 0;
    s.start();
    while (sc.hasNext()) {
      totalWords++;
      set.add(sc.next());
    }
    s.stop();
    sc.close();

    showResultsAndWords(set, s, totalWords, set.size());
  }
 public BoundFrame primePattern(String name, ISet<DMIElem> xV) {
   NamedPattern p = find(name);
   if (p != null) {
     int fCnt = p.itsInitialFrame.itsPatternDefinition.itsFormalArgumentCount;
     int aCnt = xV.size();
     if (aCnt > fCnt) lang.errMsg("too many parameters to pattern: " + name);
     BoundFrame ans = new BoundFrame(p.itsInitialFrame, true);
     for (int i = 0; i < aCnt; i++) {
       DMIElem m = xV.get(i);
       if (m != null) ans.bindInputVariable(i, m);
     }
     return ans;
   }
   return null;
 }
Example #6
0
 public void memUsage(MemRefCount mrc) {
   mrc.objCount++;
   mrc.atrCount += 5;
   mrc.strCount += 1;
   mrc.strSize += itsName.length();
   itsConceptSet.memUsage(mrc);
 }
 /**
  * create a SortedSet out of an unsorted set. <br>
  *
  * @param other != null
  */
 public SortedSet(ISet<E> other) {
   ArrayList<E> temp = new ArrayList<E>();
   Iterator<E> otherIterator = other.iterator();
   while (otherIterator.hasNext()) temp.add(otherIterator.next());
   mergeSort(temp);
   myCon = temp;
 }
 @Test
 public void testHazelcastInstances() {
   assertNotNull(map1);
   assertNotNull(map2);
   assertNotNull(multiMap);
   assertNotNull(queue);
   assertNotNull(topic);
   assertNotNull(set);
   assertNotNull(list);
   assertNotNull(executorService);
   assertNotNull(idGenerator);
   assertNotNull(atomicLong);
   assertNotNull(atomicReference);
   assertNotNull(countDownLatch);
   assertNotNull(semaphore);
   assertNotNull(lock);
   assertEquals("map1", map1.getName());
   assertEquals("map2", map2.getName());
   assertEquals("testMultimap", multiMap.getName());
   assertEquals("testQ", queue.getName());
   assertEquals("testTopic", topic.getName());
   assertEquals("set", set.getName());
   assertEquals("list", list.getName());
   assertEquals("idGenerator", idGenerator.getName());
   assertEquals("atomicLong", atomicLong.getName());
   assertEquals("atomicReference", atomicReference.getName());
   assertEquals("countDownLatch", countDownLatch.getName());
   assertEquals("semaphore", semaphore.getName());
 }
Example #9
0
 public ISet<DMIElem> traverse(
     ISet<DMIElem> inNodes,
     BoundFork inPatterns,
     boolean infer,
     boolean loop,
     ISet<DMIElem> suggested) {
   if (infer) {
     ISet<DMIElem> ans = new XSetList<DMIElem>(XSetList.AsSet);
     ISet<DMIElem> xV = new XSetList<DMIElem>(XSetList.AsSet);
     for (; ; ) {
       IList<InferredRelationship> inferSet = new XSetList<InferredRelationship>();
       ISet<DMIElem> res = traverse(inNodes, inPatterns, inferSet, suggested);
       ans.merge(res);
       for (int i = 0; i < inferSet.size(); i++) {
         InferredRelationship ifr = inferSet.get(i);
         int cnt = itsConceptMgr.itsGraph.getMaxIndex();
         DMIElem m = itsConceptMgr.enterStatement(ifr.sb, ifr.vb, ifr.ob, false);
         ans.add(m);
         ans.add(ifr.sb);
         ans.add(ifr.ob);
         if (itsConceptMgr.itsGraph.getMaxIndex() > cnt) xV.add(m);
       }
       if (loop && xV.size() > 0) continue;
       break;
     }
     return ans; // xV; only the inferred nodes
   }
   return traverse(inNodes, inPatterns, null, suggested);
 }
Example #10
0
 public void addConcept(DMIElem e) {
   itsGraph.setIndex(e); // this will error if the item is already in some other subgraph
   assert e.itsSubgraph == null : "DMISubgraph.AddConcept: subgraph not null";
   e.itsSubgraph = this;
   itsConceptSet.addToList(e);
   // #if ( gOptDynInline ) {
   if (e.isStatement()) {
     itsGraph.itsCacheBuilder.DynamicCachingAndInferencing(e);
   }
   // #}
 }
Example #11
0
 public void trim() {
   itsConceptSet.trim();
 }
Example #12
0
  public static void main(String[] args) {

    UnsortedSet<Integer> s1 = new UnsortedSet<Integer>();
    for (int i = 1; i <= 10; i++) {
      s1.add(i);
    }

    UnsortedSet<Integer> s2 = new UnsortedSet<Integer>();
    for (int i = 5; i < 15; i++) {
      s2.add(i);
    }

    // Test 1: size method
    System.out.print("Test 1, UnsortedSet  size method: ");
    if (s1.size() == 10) System.out.println("passed");
    else System.out.println("failed");

    // Test 2: add method
    System.out.print("Test 2, UnsortedSet  add method: ");
    s1.add(11);
    if (s1.contains(11)) {
      System.out.println("passed");
    } else {
      System.out.println("failed");
    }

    // Test 3: toString method
    System.out.print("Test 3, UnsortedSet toString method: ");
    if (s1.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)")) {
      System.out.println("passed");
    } else {
      System.out.println("failed");
    }

    // Test 4: add all method
    System.out.print("Test 4, UnsortedSet  add all method: ");
    s1.addAll(s2);
    if (s1.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)")) {
      System.out.println("passed");
    } else {
      System.out.println("failed");
    }

    // Test 5: remove method
    System.out.print("Test 5, UnsortedSet remove method: ");
    for (int i = 11; i < 15; i++) {
      s1.remove(i);
    }
    if (s1.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)")) {
      System.out.println("passed");
    } else {
      System.out.println("failed");
    }

    // Test 6: clear method
    System.out.print("Test 6, UnsortedSet clear method: ");
    s1.clear();
    if (s1.size() == 0) {
      System.out.println("passed");
    } else {
      System.out.println("failed");
    }

    for (int i = 1; i <= 10; i++) {
      s1.add(i);
    }

    // Test 7: contains method
    System.out.print("Test 7, UnsortedSet contains method: ");
    if (!s1.contains(999)) {
      System.out.println("passed");
    } else {
      System.out.println("failed");
    }

    // Test 8: contains all method
    System.out.print("Test 8, UnsortedSet contains all method: ");
    if (!s1.containsAll(s2)) System.out.println("passed");
    else System.out.println("failed");

    // Test 9: union method
    System.out.print("Test 9, UnsortedSet union method: ");
    ISet<Integer> s3 = s1.union(s2);
    if (s3.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)"))
      System.out.println("passed");
    else System.out.println("failed");

    // Test 10: difference method
    System.out.print("Test 10, UnsortedSet difference method: ");
    s3 = s1.difference(s2);
    if (s3.toString().equals("(1, 2, 3, 4)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 11: intersection method
    System.out.print("Test 11, UnsortedSet intersection method: ");
    s3 = s2.intersection(s1);
    if (s3.toString().equals("(5, 6, 7, 8, 9, 10)")) System.out.println("passed");
    else System.out.println("failed");

    // The following test cases are for sorted set

    // Test 12: Create a sorted set with unsorted set
    UnsortedSet<Integer> list1 = new UnsortedSet<Integer>();
    list1.add(9);
    list1.add(3);
    list1.add(1);
    list1.add(5);
    SortedSet<Integer> list2 = new SortedSet<Integer>(list1);
    System.out.print("Test 12, SortedSet constructor method: ");
    if (list2.toString().equals("(1, 3, 5, 9)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 13: add method
    System.out.print("Test 13, SortedSet add method: ");
    list2.add(7);
    if (list2.toString().equals("(1, 3, 5, 7, 9)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 14: add all method
    System.out.print("Test 14, SortedSet add all method: ");
    list1.clear();
    list1.add(1);
    list1.add(3);
    list1.add(6);
    list1.add(4);
    list2.addAll(list1);
    if (list2.toString().equals("(1, 3, 4, 5, 6, 7, 9)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 15: remove method
    System.out.print("Test 15, SortedSet  remove method: ");
    list2.remove(4);
    list2.remove(6);
    if (list2.toString().equals("(1, 3, 5, 7, 9)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 16: clear and size method
    System.out.print("Test 16, SortedSet clear and size method: ");
    list2.clear();
    if (list2.size() == 0) System.out.println("passed");
    else System.out.println("failed");

    // Test 17: contains method
    System.out.print("Test 17, SortedSet contains method: ");
    list2.add(4);
    list2.add(2);
    list2.add(3);
    list2.add(23);
    list2.add(9999);
    if (list2.contains(9999)) System.out.println("passed");
    else System.out.println("failed");

    // Test 18: contains all method
    System.out.print("Test 18, SortedSet contains all method: ");
    if (!list2.containsAll(list1)) System.out.println("passed");
    else System.out.println("failed");

    // Test 19: union method
    System.out.print("Test 19, SortedSet union method: ");
    ISet<Integer> resultList = list2.union(list1);
    if (resultList.toString().equals("(1, 2, 3, 4, 6, 23, 9999)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 20: difference method
    System.out.print("Test 20, SortedSet difference method: ");
    resultList = list1.difference(list2);
    if (resultList.toString().equals("(1, 6)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 21: intersection method
    System.out.print("Test 21, SortedSet intersection method: ");
    resultList = list2.intersection(list1);
    if (resultList.toString().equals("(3, 4)")) System.out.println("passed");
    else System.out.println("failed");

    // Test 22: minimum method
    System.out.print("Test 22, SortedSet min method: ");
    if (list2.min() == 2) System.out.println("passed");
    else System.out.println(false);

    // Test 23: maximum method
    System.out.print("Test 23, SortedSet max method: ");
    if (list2.max() == 9999) System.out.println("passed");
    else System.out.println("failed");

    // Test 24: SortedSet size method
    System.out.print("Test 24, SortedSet size method: ");
    if (list2.size() == 5) System.out.println("passed");
    else System.out.println("failed");

    // Test 25: UnsortedSet size method
    System.out.print("Test 25, UnsortedSet size method");
    if (list1.size() == 4) System.out.println("passed");
    else System.out.println("failed");

    //         CS314 Students. Uncomment this section when ready to
    //         run your experiments
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      System.out.println("Unable to change look and feel");
    }
    Scanner sc = new Scanner(System.in);
    String response = "";
    do {
      largeTest();
      System.out.print("Another file? Enter y to do another file: ");
      response = sc.next();
    } while (response != null
        && response.length() > 0
        && response.substring(0, 1).equalsIgnoreCase("y"));
  }
Example #13
0
  private ISet<DMIElem> traverse(
      ISet<DMIElem> inNodes,
      BoundFork inPatterns,
      IList<InferredRelationship> inferSet,
      ISet<DMIElem> suggested) {
    BoundFork currPatterns = inPatterns;

    ISet<DMIElem> currNodes = new XSetList<DMIElem>(XSetList.AsSet);
    ISet<DMIElem> currLinks = new XSetList<DMIElem>(XSetList.AsSet);

    for (DMIElem src : inNodes) if (src != null) setVisited(src);

    for (DMIElem src : inNodes) if (src != null) stepFromConcept(src, currNodes, currLinks);

    if (suggested != null) {
      for (DMIElem src : suggested) classifyConcept(src, currNodes, currLinks);
    }

    ISet<DMIElem> ansSet = new XSetList<DMIElem>(XSetList.AsSet);
    ISet<BoundFrame> nonRejectedCandidates = new XSetList<BoundFrame>(XSetList.AsSet);

    int iterCnt = 0;

    for (; ; ) {
      ++iterCnt;

      if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0)
        Tracing.gTraceFile.println("---- Iteration " + iterCnt + " ----");

      // pattern match exhausted?  if so, there's nothing left to match.
      if (currPatterns.isEmpty()) break;

      IList<BoundFrame> lbf = currPatterns.getFrames();
      int cnt = lbf.size();

      if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0) {
        Tracing.gTraceFile.println("frames for iteration:");
        for (int i = 0; i < cnt; i++) {
          BoundFrame fr = lbf.get(i);
          fr.traceOut();
        }
        Tracing.gTraceFile.println("==========");
      }

      // Pass 1 search new frames for successes or success roots
      for (int i = 0; i < cnt; i++) {
        BoundFrame fr = lbf.get(i);
        if (fr.succcessPathComplete()) {
          if (fr.couldBeRejected()) {
            if (fr.markAsSuccessRoot()) {

              if ((Tracing.gTraceSet & Tracing.TraceWave) != 0) {
                Tracing.gTraceFile.println("$$$ Adding frame root: ");
                fr.traceOut();
              }

              boolean b = nonRejectedCandidates.add(fr);

              if (!b && (Tracing.gTraceSet & Tracing.TraceWave) != 0)
                Tracing.gTraceFile.println(" ****** was already on root list");
            }
          } else if (fr.completed(ansSet, inferSet, null)) {

            if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0) {
              Tracing.gTraceFile.print("$$$Taking result frame: ");
              int st = Tracing.gTraceSet;
              Tracing.gTraceSet |= Tracing.TraceFrameX;
              fr.traceOut();
              Tracing.gTraceFile.println();
              Tracing.gTraceSet = st;
            }

            if (fr.whenCompletedisFinished()) lbf.clear(i);
          }
        }
      }

      // Pass 2 search for rejections
      for (int i = 0; i < cnt; i++) {
        BoundFrame fr = lbf.get(i);
        if (fr != null) {
          if (fr.rejected()) {
            lbf.clear(i);
            BoundFrame successRoot = fr.getSuccessRoot();

            if (successRoot != null) nonRejectedCandidates.remove(successRoot);

            if ((Tracing.gTraceSet & Tracing.TraceWave) != 0) {
              Tracing.gTraceFile.println("$$$ Rejecting frame: ");
              fr.traceOut();
              if (successRoot != null) {
                Tracing.gTraceFile.println(" Which takes out root frame: ");
                successRoot.traceOut();
              }
            }
          }
        }
      }
      lbf.trim();

      if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0) {
        Tracing.gTraceFile.println("frames after checking success:");
        for (int i = 0; i < lbf.size(); i++) {
          BoundFrame fr = lbf.get(i);
          fr.traceOut();
        }
        Tracing.gTraceFile.println("==========");
      }

      cnt = currNodes.size();
      for (int i = 0; i < cnt; i++) {
        DMIElem m = currNodes.get(i);
        stepFromNode(m, currLinks);
      }

      // input set exhausted?  if so, there's nothing left to traverse.
      if (currLinks.isEmpty()) break;

      BoundFork nextPatterns = new BoundFork();
      ISet<DMIElem> nextNodes = new XSetList<DMIElem>(XSetList.AsSet);
      ISet<DMIElem> nextLinks = new XSetList<DMIElem>(XSetList.AsSet);
      ISet<BoundFork[]> updatedSubpatterns = new XSetList<BoundFork[]>(XSetList.AsSet);

      cnt = currLinks.size();
      for (int i = 0; i < cnt; i++) {
        DMIElem m = currLinks.get(i);
        if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0)
          Tracing.gTraceFile.println("visiting: " + m.itsIndex);

        // all patterns have to see all statements,
        //  even newly generated patterns from current generation
        BoundFork morePatterns = new BoundFork();
        accept(m, nextPatterns, morePatterns, nextNodes, nextLinks, updatedSubpatterns);
        nextPatterns.mergeIntoFork(morePatterns);

        // existing patterns have to see all statements,
        // and if they cannot advance, they'll be retired this generation
        accept(m, currPatterns, nextPatterns, nextNodes, nextLinks, updatedSubpatterns);
      }

      // $21$: carry frames over whose subforks are modified
      lbf = currPatterns.getFrames();
      cnt = lbf.size();
      for (int i = 0; i < cnt; i++) {
        BoundFrame fr = lbf.get(i);
        if (fr.usesSubForkIn(updatedSubpatterns)) {
          if ((Tracing.gTraceSet & Tracing.TraceFrame) != 0)
            Tracing.gTraceFile.println("carrying over frame #" + fr.itsIndex);
          nextPatterns.addFrame(fr);
        }
      }

      currNodes = nextNodes; // switch over to new set of nodes
      currLinks = nextLinks; // switch over to new set of links
      currPatterns = nextPatterns; // retire all patterns, having seen a full step
    }

    // process nonRejectedCandidates list
    for (int i = 0; i < nonRejectedCandidates.size(); i++) {
      BoundFrame fr = nonRejectedCandidates.get(i);
      boolean y = fr.completed(ansSet, inferSet, null);
      if (y && (Tracing.gTraceSet & Tracing.TraceFrame) != 0)
        Tracing.gTraceFile.println("took: " + fr.itsIndex);
    }

    return ansSet;
  }