gnu.trove.map.hash.TIntIntHashMap Java Examples

The following examples show how to use gnu.trove.map.hash.TIntIntHashMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public TIntObjectHashMap<TIntIntHashMap> getEntityKeywordIntersectionCount(Entities entities) throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<TIntIntHashMap>();

  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      String[] tokens = null;
      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          tokens = eKps[i].split(" ");
        } else {
          int count = Integer.parseInt(eKps[i]);
          for (String token : tokens) {
            counts.adjustOrPutValue(DataAccess.getIdForWord(token), count, count);
          }
        }
      }
    }
  }
  return isec;
}
 
Example #2
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * check resource profile on each host
 *
 * @param changes  the resource profiles
 * @param initFree the initial amount of free resources
 * @return the satisfaction status
 */
private ESat checkProfiles(TIntIntHashMap[][] changes, int[][] initFree) {
    boolean ok = true;
    for (int h = 0; h < nbHosts; h++) {
        TIntObjectHashMap<int[]> myChanges = myChanges(changes[h]);
        int[] moments = myChanges.keys(new int[myChanges.size()]);
        Arrays.sort(moments);
        for (int t : moments) {
            boolean bad = false;
            for (int d = 0; d < nbDims; d++) {
                initFree[h][d] += myChanges.get(t)[d];
                if (initFree[h][d] < 0) {
                    bad = true;
                }
            }
            if (bad) {
                ok = false;
                break;
            }
        }
    }
    return ESat.eval(ok);
}
 
Example #3
Source File: MaxOnlineSplitter.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final boolean c = cstr.isContinuous();
    final int q = cstr.getAmount();
    return SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition).
            forEachPartition(new IterateProcedure<Node>() {

                private boolean first = true;

                @Override
                public boolean extract(SplittableElementSet<Node> index, int idx, int from, int to) {
                    if (!first) {
                        return false;
                    }
                    if (to - from >= 1) {
                        partitions.get(idx).getSatConstraints().add(new MaxOnline(new ElementSubSet<>(index, idx, from, to), q, c));
                        first = false;
                    }
                    return true;
                }
            });

}
 
Example #4
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * check dStart[dt] >= earlyStart[dHost[dt]] for all dTasks
 *
 * @param changes the profile. Will be updated with the dSlices value
 * @return the satisfaction status
 */
private ESat checkDSlices(TIntIntHashMap[][] changes) {
    for (int dt = 0; dt < dHosters.length; dt++) {
        if (!dHosters[dt].isInstantiated() || !dStarts[dt].isInstantiated()) {
            return ESat.UNDEFINED;
        }
        int h = dHosters[dt].getValue();
        int t = dStarts[dt].getValue();
        if (t < earlyStarts[h].getValue()) {
            return ESat.FALSE;
        }
        for (int d = 0; d < nbDims; d++) {
            changes[h][d].put(t, changes[h][d].get(t) - dUsages[dt][d]);
        }
    }
    return ESat.TRUE;
}
 
Example #5
Source File: MaterializeMIWeights.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntIntHashMap getCounts(String table, String key) throws SQLException {
  TIntIntHashMap counts = new TIntIntHashMap();
  Connection con = EntityLinkingManager.getConnectionForDatabase(EntityLinkingManager.DB_AIDA);
  Statement stmt = con.createStatement();
  con.setAutoCommit(false);
  stmt.setFetchSize(1000000);
  ResultSet rs = stmt.executeQuery("SELECT " + key + ",count FROM " + table);
  while (rs.next()) {
    int keyThing = rs.getInt(key);
    int count = rs.getInt("count");
    counts.put(keyThing, count);
  }
  con.setAutoCommit(true);
  EntityLinkingManager.releaseConnection(con);
  return counts;
}
 
Example #6
Source File: SuperdocEntityKeyphraseCountCollector.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private void writeToFile(TIntObjectHashMap<TIntIntHashMap> superdocKeyphraseCounts) throws IOException, SQLException {
  int eCount = 0;

  logger.info("Writing entity-keyphrase pairs for " + superdocKeyphraseCounts.size() + " entities");

  for (int eid : superdocKeyphraseCounts.keys()) {

    if ((++eCount % 100000) == 0) {
      double percent = (double) eCount / (double) superdocKeyphraseCounts.size();

      logger.info("Wrote " + eCount + " entities (" + new DecimalFormat("#.##").format(percent) + ")");
    }

    TIntIntHashMap keyphraseCounts = superdocKeyphraseCounts.get(eid);

    for (int kid : keyphraseCounts.keys()) {
      int count = keyphraseCounts.get(kid);

      writer.write(eid + "\t" + kid + "\t" + String.valueOf(count));
      writer.newLine();
    }
  }
}
 
Example #7
Source File: SeqSplitter.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean split(Seq cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final List<VM> seq = cstr.getInvolvedVMs();
    return SplittableElementSet.newVMIndex(seq, vmsPosition).
            forEachPartition(new IterateProcedure<VM>() {

                private boolean first = true;

                @Override
                public boolean extract(SplittableElementSet<VM> index, int idx, int from, int to) {
                    int size = to - from;
                    if (!first) {
                        throw new UnsupportedOperationException("Splitting a Seq over multiple partitions is not supported");
                    }
                    if (size == seq.size()) {
                        partitions.get(idx).getSatConstraints().add(new Seq(seq));
                        first = false;
                    }
                    return true;
                }
            });
}
 
Example #8
Source File: PartialOrder.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public PartialOrder(DifferenceSets differenceSets, int columnIndexToSkip) {
	TIntIntHashMap orderMap = new TIntIntHashMap();

	for (DifferenceSet differenceSet : differenceSets) {
		// increase the cover count for set columns
		int bitIndex = columnIndexToSkip;
		while (bitIndex < differenceSet.getNumberOfColumns()) {
			int currentNextSetBit = differenceSet.nextSetBit(bitIndex);
			if (currentNextSetBit != -1) {
				bitIndex = currentNextSetBit + 1;
				orderMap.putIfAbsent(currentNextSetBit, 0);
				orderMap.increment(currentNextSetBit);
			} else {
				bitIndex = differenceSet.getNumberOfColumns();
			}
		}
	}
	
	for (int index : orderMap.keys()) {
		this.add(new CoverOrder(index, orderMap.get(index)));
	}
	
	Collections.sort(this, Collections.reverseOrder());

}
 
Example #9
Source File: SplittableElementSetTest.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test(dependsOnMethods = "testNewVMSet")
public void testOrdering() {
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();
    Random rnd = new Random();
    for (int i = 0; i < 10; i++) {
        l.add(new VM(i));
        index.put(i, rnd.nextInt(3));
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
    System.err.println(s);
    List<VM> values = s.getValues();
    for (int i = 0; i < values.size() - 1; i++) {
        Assert.assertTrue(index.get(values.get(i).id()) <= index.get(values.get(i + 1).id()));
    }
}
 
Example #10
Source File: DumpVersionTroveIntKey.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Timestamp timestamp) {
	this.timestamp = Revision.compressTime(timestamp.getTime());

	/**
	 * filled in revisions
	 */
	pageIdRevMap = new HashMap<Integer, Long>();
	textIdPageIdMap = new TIntIntHashMap();

	/**
	 * filled in pages
	 */
	pPageIdNameMap = new HashMap<Integer, String>();
	pNamePageIdMap = new TIntIntHashMap();

	cNamePageIdMap = new TIntIntHashMap();
	rPageIdNameMap = new HashMap<Integer, String>();

	/**
	 * filled in categories
	 */
	disambiguations = new TIntHashSet();
}
 
Example #11
Source File: DumpVersionJDKGeneric.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Timestamp timestamp) {
	this.timestamp = Revision.compressTime(timestamp.getTime());

	/**
	 * filled in revisions
	 */
	pageIdRevMap = new HashMap<Integer, Long>();
	textIdPageIdMap = new TIntIntHashMap();

	/**
	 * filled in pages
	 */
	pPageIdNameMap = new HashMap<Integer, String>();
	pNamePageIdMap = new HashMap<KeyType, Integer>();

	cNamePageIdMap = new HashMap<KeyType, Integer>();
	rPageIdNameMap = new HashMap<Integer, String>();

	/**
	 * filled in categories
	 */
	disambiguations = new TIntHashSet();
}
 
Example #12
Source File: DefaultMapping.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create a new mapping.
 */
@SuppressWarnings("unchecked")
public DefaultMapping() {

    nodeState = new Set[2];
    nodeState[ONLINE_STATE] = new THashSet<>();
    nodeState[OFFLINE_STATE] = new THashSet<>();

    vmReady = new THashSet<>();

    place = new TIntObjectHashMap<>();

    host = new TIntObjectHashMap[2];
    host[RUNNING_STATE] = new TIntObjectHashMap<>();
    host[SLEEPING_STATE] = new TIntObjectHashMap<>();

    st = new TIntIntHashMap(100, 0.5f, -1, -1);
}
 
Example #13
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
public TIntObjectHashMap<TIntIntHashMap> getEntityKeyphraseIntersectionCount(Entities entities) throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<TIntIntHashMap>();
  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      int currentKp = -1;
      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          currentKp = DataAccess.getIdForWord(eKps[i]);
        } else {
          int count = Integer.parseInt(eKps[i]);
          counts.put(currentKp, count);
        }
      }
    }
  }
  return isec;
}
 
Example #14
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ESat isEntailed() {

    //A hashmap to save the changes of each node (relatives to the previous moment) and each dimension
    TIntIntHashMap[][] changes = new TIntIntHashMap[nbHosts][nbDims];
    int[][] initFree = new int[nbHosts][];
    for (int h = 0; h < nbHosts; h++) {
        for (int d = 0; d < nbDims; d++) {
            changes[h][d] = new TIntIntHashMap();
        }
        initFree[h] = Arrays.copyOf(capacities[h], capacities[h].length);
    }

    ESat sat = checkDSlices(changes);
    if (ESat.TRUE != sat) {
        return sat;
    }

    sat = checkCSlices(changes, initFree);
    if (ESat.TRUE != sat) {
        return sat;
    }

    return checkProfiles(changes, initFree);
}
 
Example #15
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * check cEnd[ct] <= lastEnd[cHost[ct]] for all cTasks.
 *
 * @param changes  will be modified
 * @param initFree the initial amount of free resources
 * @return the satisfaction status
 */
private ESat checkCSlices(TIntIntHashMap[][] changes, int[][] initFree) {

    for (int ct = 0; ct < cHosters.length; ct++) {
        if (!cHosters[ct].isInstantiated() || !cEnds[ct].isInstantiated()) {
            return ESat.UNDEFINED;
        }
        int h = cHosters[ct].getValue();
        int t = cEnds[ct].getValue();
        if (t > lastEnds[h].getValue()) {
            return ESat.FALSE;
        }
        for (int d = 0; d < nbDims; d++) {
            changes[h][d].put(t, changes[h][d].get(t) + cUsages[ct][d]);
            initFree[h][d] -= cUsages[ct][d];
        }
    }
    return ESat.TRUE;
}
 
Example #16
Source File: KeywordsStatCollector.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private void storeKeywordsIntoDB(TIntIntHashMap keywordsCounts) throws SQLException {
  Connection con = null;

  con = EntityLinkingManager.getConnectionForDatabase(EntityLinkingManager.DB_AIDA);
  Statement schemaStatement = con.createStatement();

  String sql = "CREATE TABLE " + DataAccessSQL.KEYWORD_COUNTS + "(keyword INTEGER, count INTEGER)";
  schemaStatement.execute(sql);
  schemaStatement.close();

  final PreparedStatement insertStatement;
  insertStatement = DBUtil.getAutoExecutingPeparedStatement(con, "INSERT INTO " + DataAccessSQL.KEYWORD_COUNTS + " VALUES(?,?)", 1_000_000);
  con.setAutoCommit(false);

  keywordsCounts.forEachEntry(new TIntIntProcedure() {

    @Override public boolean execute(int keyword, int count) {
      try {
        insertStatement.setInt(1, keyword);
        insertStatement.setInt(2, count);
        insertStatement.addBatch();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      return true;
    }
  });
  insertStatement.executeBatch();
  con.commit();
  insertStatement.close();
  con.setAutoCommit(true);

  schemaStatement = con.createStatement();
  logger.info("Creating indexes ...");
  sql = "CREATE INDEX keywords_index ON " + DataAccessSQL.KEYWORD_COUNTS + " using btree (keyword);";
  schemaStatement.execute(sql);
  schemaStatement.close();

  EntityLinkingManager.releaseConnection(con);
}
 
Example #17
Source File: SplittableElementSetTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testNewNodeSet() {
    List<Node> l = new ArrayList<>();
    TIntIntHashMap m = new TIntIntHashMap();
    for (int i = 0; i < 10; i++) {
        l.add(new Node(i));
        m.put(i, i % 2);
    }
    SplittableElementSet<Node> s = SplittableElementSet.newNodeIndex(l, m);
    for (Node v : s.getValues()) {
        Assert.assertTrue(v.id() >= 0 && v.id() < 10);
    }
    Assert.assertEquals(s.size(), l.size());
    Assert.assertEquals(s.getRespectiveIndex(), m);
}
 
Example #18
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override public TIntObjectHashMap<TIntIntHashMap> getEntityUnitIntersectionCount(Entities entities, UnitType unitType)
    throws EntityLinkingDataAccessException {
  switch (unitType) {
    case KEYWORD:
    case BIGRAM:
      return getEntityUnitIntersectionCountInternal(entities, unitType);
    default:
      return null;
  }
}
 
Example #19
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private TIntObjectHashMap<TIntIntHashMap> getEntityUnitIntersectionCountInternal(Entities entities, UnitType unitType)
    throws EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntIntHashMap> isec = new TIntObjectHashMap<>();

  for (String[] eKps : allEntityKeyphrases) {
    int entity = DataAccess.getInternalIdForKBEntity(getTestKBEntity(eKps[0]));
    TIntIntHashMap counts = new TIntIntHashMap();
    isec.put(entity, counts);

    if (eKps.length > 1) {
      String[] keyphrase = null;

      for (int i = 1; i < eKps.length; ++i) {
        if (i % 2 == 1) {
          keyphrase = eKps[i].split(" ");
        } else {
          int count = Integer.parseInt(eKps[i]);

          Set<String[]> ngrams = StringUtils.getNgrams(keyphrase, unitType.getUnitSize());
          for (String[] ngram : ngrams) {
            String ngramString = String.join(" ", ngram);
            counts.adjustOrPutValue(DataAccess.getIdForWord(ngramString), count, count);
          }
        }
      }
    }
  }
  return isec;
}
 
Example #20
Source File: AliasedCumulatives.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ESat isSatisfied(int[] dHostersVals, int[] dStartsVals, int[] cHostersVals, int[] cEndsVals) {
    //A map to save the changes of the resource (relatives to the previous moment) in the resources distribution
    TIntIntHashMap[] changes = new TIntIntHashMap[nbDims];
    int[] currentFree = Arrays.copyOf(capacities, capacities.length);

    for (int i = 0; i < nbDims; i++) {
        changes[i] = new TIntIntHashMap();
        for (int j = 0; j < dHostersVals.length; j++) {
            //for each placed dSlices, we get the used resource and the moment the slice arrives on it
            if (isIn(dHostersVals[j])) {
                changes[i].put(dStartsVals[j], changes[i].get(dStartsVals[j]) - dUsages[i][j]);
            }
        }

        for (int j = 0; j < cHostersVals.length; j++) {
            if (isIn(cHostersVals[j])) {
                changes[i].put(cEndsVals[j], changes[i].get(cEndsVals[j]) + cUsages[i][j]);
                currentFree[i] -= cUsages[i][j];
            }
        }

        for (int x = 0; x < changes[i].keys().length; x++) {
            currentFree[i] += changes[i].get(x);
            if (currentFree[i] < 0) {
                return ESat.FALSE;
            }
        }
    }
    return ESat.TRUE;
}
 
Example #21
Source File: LocalTaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String prettyProfile(int[] ascMoments, TIntIntHashMap prof) {
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < ascMoments.length; i++) {
        int t = ascMoments[i];
        b.append(t);
        b.append(':');
        b.append(prof.get(t));
        if (i != ascMoments.length - 1) {
            b.append(' ');
        }
    }
    return b.toString();
}
 
Example #22
Source File: ConnectedComponentsDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void merge(TIntIntHashMap linked, int start, int target) {
	if (start == target)
		return;

	final int old = linked.get(start);

	if (old > target) {
		linked.put(start, target);
		merge(linked, old, target);
	} else {
		merge(linked, target, old);
	}
}
 
Example #23
Source File: ElementSubSetTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
    Model mo = new DefaultModel();
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();

    for (int i = 0; i < 10; i++) {
        l.add(mo.newVM());
        index.put(i, i % 2);
    }

    SplittableElementSet<VM> si = SplittableElementSet.newVMIndex(l, index);
    List<VM> values = si.getValues();

    ElementSubSet<VM> p1 = new ElementSubSet<>(si, 0, 0, 5);
    //test contains()
    Assert.assertTrue(p1.contains(values.get(0)));
    Assert.assertFalse(p1.contains(values.get(5)));

    //test containsAll()
    Assert.assertFalse(p1.containsAll(l));

    //test size()
    Assert.assertEquals(p1.size(), 5);
    Assert.assertFalse(p1.isEmpty());

    System.out.println(p1);
    //test iterator
    for (VM v : p1) {
        Assert.assertEquals(v.id() % 2, 0);
    }
}
 
Example #24
Source File: IEJoin.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private static int[] getPermutationArray(int[] l2, int[] l1) {
	final int count = l1.length;
	TIntIntMap map = new TIntIntHashMap(count);
	for (int i = 0; i < count; ++i) {
		map.put(l1[i], i);
	}
	int[] result = new int[count];
	for (int i = 0; i < count; ++i) {
		result[i] = map.get(l2[i]);
	}
	return result;
}
 
Example #25
Source File: InputTextWrapper.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public InputTextWrapper(Context context, UnitType unitType, boolean removeStopwords) throws EntityLinkingDataAccessException {
  logger.debug("Wrapping input text.");
  mentionToIgnore = null;
  this.unitType = unitType;
  int unitLength = unitType.getUnitSize();
  if (context.getTokenCount() < unitLength) return;
  List<String> unitStrings = new ArrayList<>(context.getTokenCount());
  Queue<String> curTokens = new ArrayDeque<>(unitLength);
  String[] curTokensArray = new String[unitLength];
  for (String token : context.getTokens()) {
    curTokens.add(token);
    if (curTokens.size() == unitLength || (!curTokens.isEmpty() && curTokens.size() - 1 == unitLength)) {
      unitStrings.add(UnitBuilder.buildUnit(curTokens.toArray(curTokensArray)));
      curTokens.remove();
    }
  }

  logger.debug("Get ids for words.");
  TObjectIntHashMap<String> wordIds = DataAccess.getIdsForWords(unitStrings);
  units = new int[unitStrings.size()];
  unitCounts = new TIntIntHashMap((int) (wordIds.size() / Constants.DEFAULT_LOAD_FACTOR), Constants.DEFAULT_LOAD_FACTOR);
  numOfUnits = 0;
  for (int i = 0; i < unitStrings.size(); i++) {
    int unitId = wordIds.get(unitStrings.get(i));
    if (unitId == 0) continue;

    logger.debug("Get contract term for unit id {}.", unitId);
    int contractedUnitId = DataAccess.contractTerm(unitId);
    if (contractedUnitId != 0) unitId = contractedUnitId;
    if (removeStopwords && StopWord.isStopwordOrSymbol(unitId, Language.getLanguageForString("en")))  continue;
    units[i] = unitId;
    unitCounts.adjustOrPutValue(unitId, 1, 1);
    numOfUnits++;
  }
}
 
Example #26
Source File: OfflineSplitterTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void simpleTest() {
    OfflineSplitter splitter = new OfflineSplitter();

    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    Node n = m0.newNode();
    m0.getMapping().addOfflineNode(n);
    m0.getMapping().addOfflineNode(m0.newNode(1));

    Model m1 = new DefaultModel();

    m1.getMapping().addOfflineNode(m1.newNode(2));
    m1.getMapping().addOfflineNode(m1.newNode(3));

    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));

    Set<Node> all = new HashSet<>(m0.getMapping().getAllNodes());
    all.addAll(m1.getMapping().getAllNodes());

    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);

    //Only nodes in m0
    Offline oSimple = new Offline(n);
    Assert.assertTrue(splitter.split(oSimple, null, instances, new TIntIntHashMap(), nodeIndex));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(oSimple));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(oSimple));
}
 
Example #27
Source File: PreserveSplitterTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void simpleTest() {
    PreserveSplitter splitter = new PreserveSplitter();

    List<Instance> instances = new ArrayList<>();
    Model m0 = new DefaultModel();
    VM v = m0.newVM(1);
    m0.getMapping().addReadyVM(v);
    m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
    Model m1 = new DefaultModel();
    m1.getMapping().addReadyVM(m1.newVM(3));
    m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
    m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));


    instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
    instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));

    TIntIntHashMap index = Instances.makeVMIndex(instances);
    Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
    all.addAll(m1.getMapping().getAllVMs());


    //Only VMs in m0
    Preserve single = new Preserve(v, "foo", 3);
    Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
    Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
    Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
 
Example #28
Source File: DexMethod.java    From apkfile with Apache License 2.0 5 votes vote down vote up
DexMethod(DexBackedMethod method, boolean shortMethodSignatures) {
    this.method = method;
    this.shortMethodSignatures = shortMethodSignatures;

    size = method.getSize();
    accessFlags = method.getAccessFlags();
    annotationCount = method.getAnnotations().size();
    frameworkApiCounts = new TObjectIntHashMap<>();
    frameworkFieldReferenceCounts = new TObjectIntHashMap<>();
    opCounts = new TIntIntHashMap();
    stringReferenceCounts = new TObjectIntHashMap<>();
    if (method.getImplementation() != null) {
        analyze(method.getImplementation());
    }
}
 
Example #29
Source File: LonelySplitter.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean split(Lonely cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final boolean c = cstr.isContinuous();
    return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition).
            forEachPartition((index, idx, from, to) -> {
                if (to != from) {
                    partitions.get(idx).getSatConstraints().add(new Lonely(new ElementSubSet<>(index, idx, from, to), c));
                }
                return true;
            });
}
 
Example #30
Source File: YagoEntityKeyphraseCooccurrenceDataProviderIteratorTest.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private TIntObjectHashMap<TIntIntHashMap> createHashMap() {
  TIntObjectHashMap<TIntIntHashMap> overallMap = new TIntObjectHashMap<TIntIntHashMap>();
  TIntIntHashMap map1 = new TIntIntHashMap();
  overallMap.put(1, map1);

  TIntIntHashMap map2 = new TIntIntHashMap();
  map2.put(21, 100);
  map2.put(22, 101);
  map2.put(23, 102);
  overallMap.put(2, map2);

  TIntIntHashMap map3 = new TIntIntHashMap();
  map3.put(31, 103);
  map3.put(32, 104);
  map3.put(33, 105);
  overallMap.put(3, map3);

  TIntIntHashMap map4 = new TIntIntHashMap();
  overallMap.put(4, map4);

  TIntIntHashMap map5 = new TIntIntHashMap();
  map5.put(51, 106);
  map5.put(52, 107);
  map5.put(53, 108);
  overallMap.put(5, map5);

  TIntIntHashMap map6 = new TIntIntHashMap();
  overallMap.put(6, map6);

  TIntIntHashMap map7 = new TIntIntHashMap();
  overallMap.put(7, map7);

  return overallMap;
}