@Override public void toBytes(final ByteBuf buf) { buf.writeDouble(meanTickTime); buf.writeInt(tMap.size()); TIntDoubleIterator i = tMap.iterator(); while (i.hasNext()) { i.advance(); buf.writeInt(i.key()); buf.writeDouble(i.value()); } buf.writeInt(free); buf.writeInt(total); buf.writeInt(max); }
private void CreateDualConstraintForSequence(int sequenceId) throws IloException{ IloLinearNumExpr lhs = cplex.linearNumExpr(); for (int i = 0; i < sequenceFormDualMatrix[sequenceId].size(); i++) { int informationSetId = sequenceFormDualMatrix[sequenceId].get(i);// + (1-game.getSmallestInformationSetId(playerNotToSolveFor)); // map information set ID to 1 indexing. Assumes that information sets are named by consecutive integers int valueMultiplier = i == 0? 1 : -1; lhs.addTerm(valueMultiplier, dualVars[informationSetId]); } //IloLinearNumExpr rhs = cplex.linearNumExpr(); TIntDoubleIterator it = dualPayoffMatrix[sequenceId].iterator(); for ( int i = dualPayoffMatrix[sequenceId].size(); i-- > 0; ) { it.advance(); lhs.addTerm(-it.value(), strategyVarsBySequenceId[it.key()]); } dualConstraints.put(sequenceId, cplex.addGe(lhs, 0, "Dual"+sequenceId)); }
public CompressedRowMatrix compress() { CompressedRowMatrix c = new CompressedRowMatrix(rows, cols); int entryCount = getNumberOfEntries(); c.columnIndices = new int[entryCount]; c.values = new double[entryCount]; int idx = 0; for (int row = 0; row < rows; row++) { c.rowPointers[row] = idx; TIntDoubleHashMap rowMap = data.get(row); if (rowMap == null) continue; TIntDoubleIterator it = rowMap.iterator(); while (it.hasNext()) { it.advance(); c.columnIndices[idx] = it.key(); c.values[idx] = it.value(); idx++; } } return c; }
@Override public void toBytes(@Nonnull final ByteBuf buf) { buf.writeDouble(this.meanTickTime); buf.writeInt(this.tMap.size()); TIntDoubleIterator i = this.tMap.iterator(); while (i.hasNext()) { i.advance(); buf.writeInt(i.key()); buf.writeDouble(i.value()); } buf.writeInt(this.free); buf.writeInt(this.total); buf.writeInt(this.max); }
public static Map sortByValue(TIntDoubleHashMap unsortMap) { if (unsortMap.isEmpty()) { return new HashMap(); } HashMap<Integer, Double> tempMap = new HashMap<Integer, Double>(); TIntDoubleIterator iterator = unsortMap.iterator(); for ( int i = unsortMap.size(); i-- > 0; ) { iterator.advance(); tempMap.put( iterator.key(), iterator.value() ); } List<Map.Entry> list = new LinkedList<Map.Entry>(tempMap.entrySet()); // sort list based on comparator Collections.sort(list, Collections.reverseOrder(new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()) .compareTo(((Map.Entry) (o2)).getValue()); } })); Map sortedMap = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); sortedMap.put(entry.getKey(), entry.getValue()); } return sortedMap; }
/** * Sort a given {@link TIntDoubleMap} by its values * * @param map * in map * @param descending * determine the order of the sort: true - descending, false - * ascending * @return out sorted-by-values map */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static LinkedHashMap<Integer,Double> sortMapByValue(TIntDoubleMap map, final boolean descending) { List<Pair<Integer,Double>> list = new LinkedList<Pair<Integer,Double>>(); TIntDoubleIterator it1 = map.iterator(); while (it1.hasNext()) { it1.advance(); list.add(new Pair<Integer, Double>(it1.key(),it1.value())); } Collections.sort(list, new Comparator() { @Override public int compare(Object o1, Object o2) { int ret = ((Comparable) ((Pair) (o1)).getSecond()) .compareTo(((Pair) (o2)).getSecond()); if (descending) ret *= -1; return ret; } }); LinkedHashMap<Integer,Double> result = new LinkedHashMap<Integer,Double>(); Iterator<Pair<Integer,Double>> it2 = list.iterator(); while (it2.hasNext()) { Pair<Integer,Double> pair = it2.next(); result.put(pair.getFirst(), pair.getSecond()); } return result; }