本文整理匯總了Java中cern.colt.list.tdouble.DoubleArrayList類的典型用法代碼示例。如果您正苦於以下問題:Java DoubleArrayList類的具體用法?Java DoubleArrayList怎麽用?Java DoubleArrayList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DoubleArrayList類屬於cern.colt.list.tdouble包,在下文中一共展示了DoubleArrayList類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convert_xte2fte
import cern.colt.list.tdouble.DoubleArrayList; //導入依賴的package包/類
/** Given a destination-based routing in the form of an array x_te (amount of traffic targeted to node t, transmitted through link e), it returns the associated destination-based routing in the form of fractions f_te (fraction of the traffic targeted to node t that arrives (or is generated in) node a(e) (the initial node of link e), that is forwarded through link e). If a node n does not forward any traffic to a destination t, it is not possible to determine the f_te fractions for the output links of the node. Then, the function arbitrarily assumes that the 100% of the traffic to node t, would be forwarded through the shortest path (in number of hops) from n to t. Finally note that for every destination t, f_te = 0 for all the links e outgoing of node t.
*
* @param nodes List of nodes
* @param links List of links
* @param x_te For each destination node <i>t</i> (<i>t = 0</i> refers to the first node in {@code nodeIds}, <i>t = 1</i> refers to the second one, and so on), and each link <i>e</i> (<i>e = 0</i> refers to the first link in {@code linkMap.keySet()}, <i>e = 1</i> refers to the second one, and so on), {@code f_te[t][e]} represents the traffic targeted to node <i>t</i> that arrives (or is generated in) node <i>a(e)</i> (the origin node of link <i>e</i>), that is forwarded through link <i>e</i>
* @return The f_te matrix created */
public static DoubleMatrix2D convert_xte2fte(List<Node> nodes, List<Link> links, DoubleMatrix2D x_te)
{
final int N = nodes.size();
final int E = links.size();
DoubleMatrix2D A_tn = x_te.zMult(GraphUtils.getOutgoingIncidenceMatrix(nodes, links), null, 1, 0, false, true); // traffic of demand d that leaves node n
DoubleMatrix2D f_te = DoubleFactory2D.sparse.make(N, E);
IntArrayList ts = new IntArrayList();
IntArrayList es = new IntArrayList();
DoubleArrayList trafs = new DoubleArrayList();
x_te.getNonZeros(ts, es, trafs);
for (int cont = 0; cont < ts.size(); cont++)
{
final int t = ts.get(cont);
final int e = es.get(cont);
double outTraf = A_tn.get(t, links.get(e).getOriginNode().getIndex());
f_te.set(t, e, outTraf == 0 ? 0 : trafs.get(cont) / outTraf);
}
return f_te;
}
示例2: convertMatrix2Map
import cern.colt.list.tdouble.DoubleArrayList; //導入依賴的package包/類
/**
* Returns a map containing the association of each identifier pair with its corresponding
* value within the table (in linear order). First element in the table will be
* associated to the first identifier pair (in iteration order),
* second element in the table to the second identifier pair, and so on.
*
* @param <A> Row key type
* @param <B> Column key type
* @param rowIdentifiers Set of row identifiers in ascending iterator order (null values are not allowed)
* @param columnIdentifiers Set of column identifiers in ascending iterator order (duplicated and null values are not allowed)
* @param matrix Input matrix
* @return Map
*/
public static <A extends Number, B extends Number> Map<Pair<A, B>, Double> convertMatrix2Map(Set<A> rowIdentifiers, Set<B> columnIdentifiers, DoubleMatrix2D matrix)
{
List<A> rowIdentifiersList = new LinkedList<A>(rowIdentifiers);
List<B> columnIdentifiersList = new LinkedList<B>(columnIdentifiers);
IntArrayList rowIndices = new IntArrayList();
IntArrayList colIndices = new IntArrayList();
DoubleArrayList values = new DoubleArrayList();
matrix.getNonZeros(rowIndices, colIndices, values);
int elements = values.size();
Map<Pair<A, B>, Double> out = new LinkedHashMap<Pair<A, B>, Double>();
for(int i = 0; i < elements; i++)
{
int row = rowIndices.get(i);
int column = colIndices.get(i);
double value = values.get(i);
A rowId = rowIdentifiersList.get(row);
B columnId = columnIdentifiersList.get(column);
out.put(Pair.of(rowId, columnId), value);
}
return out;
}
示例3: checkMatrixDemandLinkCarriedTrafficFlowConservationConstraints
import cern.colt.list.tdouble.DoubleArrayList; //導入依賴的package包/類
/**
* <p>Checks the flow conservation constraints, and returns the traffic carried per demand.</p>
*
* @param x_de Amount of traffic from demand {@code d} (i-th row) transmitted through link e (j-th column) in traffic units
* @param xdeValueAsFractionsRespectToDemandOfferedTraffic If {@code true}, {@code x_de} values are measured as fractions [0,1] instead of traffic units
* @param optionalLayerParameter Network layer (optional)
* @return Carried traffic per demand (i-th position is the demand index and the value is the carried traffic)
*/
public DoubleMatrix1D checkMatrixDemandLinkCarriedTrafficFlowConservationConstraints(DoubleMatrix2D x_de, boolean xdeValueAsFractionsRespectToDemandOfferedTraffic, NetworkLayer... optionalLayerParameter)
{
NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter);
final double PRECISION_FACTOR = Double.parseDouble(Configuration.getOption("precisionFactor"));
if ((x_de.rows() != layer.demands.size()) || (x_de.columns() != layer.links.size()))
throw new Net2PlanException("Wrong size of x_de matrix");
if (x_de.size() > 0) if (x_de.getMinLocation()[0] < -PRECISION_FACTOR)
throw new Net2PlanException("Carried traffics cannot be negative");
final DoubleMatrix2D trafficBased_xde = xdeValueAsFractionsRespectToDemandOfferedTraffic ? DoubleFactory2D.sparse.diagonal(getVectorDemandOfferedTraffic(layer)).zMult(x_de, null) : x_de;
final DoubleMatrix2D A_ne = netPlan.getMatrixNodeLinkIncidence(layer);
final DoubleMatrix2D Div_dn = trafficBased_xde.zMult(A_ne.viewDice(), null); // out traffic minus in traffic of demand d in node n
DoubleMatrix1D r_d = DoubleFactory1D.dense.make(layer.demands.size());
for (Demand d : layer.demands)
{
final double outTrafficOfIngress = Div_dn.get(d.index, d.ingressNode.index);
final double outTrafficOfEgress = Div_dn.get(d.index, d.egressNode.index);
if (outTrafficOfIngress < -PRECISION_FACTOR)
throw new Net2PlanException("Flow conservation constraints are not met for this matrix (demand index " + d.index + ")");
if (outTrafficOfEgress > PRECISION_FACTOR)
throw new Net2PlanException("Flow conservation constraints are not met for this matrix (demand index " + d.index + ")");
if (Math.abs(outTrafficOfIngress + outTrafficOfEgress) > PRECISION_FACTOR)
throw new Net2PlanException("Flow conservation constraints are not met for this matrix (demand index " + d.index + ")");
IntArrayList ns = new IntArrayList();
DoubleArrayList vals = new DoubleArrayList();
Div_dn.viewRow(d.index).getNonZeros(ns, vals);
for (int cont = 0; cont < ns.size(); cont++)
{
final double divergence = vals.get(cont);
final int n = ns.get(cont);
if ((divergence > PRECISION_FACTOR) && (n != d.ingressNode.index))
throw new Net2PlanException("Flow conservation constraints are not met for this matrix (demand index " + d.index + ")");
if ((divergence < -PRECISION_FACTOR) && (n != d.egressNode.index))
throw new Net2PlanException("Flow conservation constraints are not met for this matrix (demand index " + d.index + ")");
}
r_d.set(d.index, outTrafficOfIngress);
}
return r_d;
}
示例4: trimUnrestrictedVariablePairs
import cern.colt.list.tdouble.DoubleArrayList; //導入依賴的package包/類
public void trimUnrestrictedVariablePairs() {
boolean checkInWhenFinished = false;
if (!checkedOut) {
checkOutMatrices();
checkInWhenFinished = true;
}
boolean pair, trim = true;
DoubleMatrix1D col1, col2, row;
IntArrayList col1Indices = new IntArrayList()
, col2Indices = new IntArrayList()
, rowIndices = new IntArrayList()
;
DoubleArrayList col1Values = new DoubleArrayList()
, col2Values = new DoubleArrayList()
, rowValues = new DoubleArrayList()
;
while (trim) {
double[] max = x.getMaxLocation();
int maxIndex = (int) max[1];
if (max[0] > 10e4) {
col1 = A.viewColumn((int) max[1]);
col1.getNonZeros(col1Indices, col1Values);
col1Indices.sort();
row = A.viewRow(col1Indices.get(0));
row.getNonZeros(rowIndices, rowValues);
for (int i = 0; i < rowIndices.size(); i++) {
if (rowIndices.get(i) != maxIndex && c.get(maxIndex) * -1 == c.get(rowIndices.get(i))) {
col2 = A.viewColumn(rowIndices.get(i));
if (col1Indices.size() == col2.cardinality()) {
col2.getNonZeros(col2Indices, col2Values);
col2Indices.sort();
pair = true;
for (int j = 0; j < col1Indices.size(); j++) {
if (col1Indices.get(j) != col2Indices.get(j)
|| col1.get(col1Indices.get(j)) * col2.get(col2Indices.get(j)) >= 0) {
pair = false;
break;
}
}
if (pair) {
if (x.get(rowIndices.get(i)) > x.get(maxIndex) / 3) {
x.set(maxIndex, x.get(maxIndex) - x.get(rowIndices.get(i)) + 1);
x.set(rowIndices.get(i), 1);
break;
}
}
}
}
if (i == rowIndices.size() - 1) trim = false;
}
}
else trim = false;
}
if (checkInWhenFinished) checkInMatrices();
}
示例5: setForwardingRules
import cern.colt.list.tdouble.DoubleArrayList; //導入依賴的package包/類
/**
* <p>Sets the forwarding rules for the given design. Any previous routing
* information (either source routing or hop-by-hop routing) will be removed.</p>
*
* @param f_de For each demand <i>d</i> (<i>d = 0</i> refers to the first demand in {@code demandIds}, <i>d = 1</i>
* refers to the second one, and so on), and each link <i>e</i> (<i>e = 0</i> refers to the first link in {@code NetPlan} object, <i>e = 1</i>
* refers to the second one, and so on), {@code f_de[d][e]} sets the fraction of the traffic from demand <i>d</i> that arrives (or is generated in) node <i>a(e)</i> (the origin node of link <i>e</i>), that is forwarded through link <i>e</i>. It must hold that for every node <i>n</i> different of <i>b(d)</i>, the sum of the fractions <i>f<sub>te</sub></i> along its outgoing links must be lower or equal than 1
* @param optionalLayerParameter Network layer (optional)
*/
public void setForwardingRules(DoubleMatrix2D f_de, NetworkLayer... optionalLayerParameter)
{
checkIsModifiable();
NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter);
layer.checkRoutingType(RoutingType.HOP_BY_HOP_ROUTING);
int D = layer.demands.size();
int E = layer.links.size();
if (f_de.rows() != D || f_de.columns() != E)
throw new Net2PlanException("'f_de' should be a " + D + " x" + E + " matrix (demands x links)");
if ((D == 0) || (E == 0))
return;
if ((D > 0) && (E > 0))
if ((f_de.getMinLocation()[0] < -1e-3) || (f_de.getMaxLocation()[0] > 1 + 1e-3))
throw new Net2PlanException("Splitting ratios must be greater or equal than zero and lower or equal than one");
final DoubleMatrix2D Aout_ne = netPlan.getMatrixNodeLinkOutgoingIncidence(layer);
final DoubleMatrix2D A_dn = f_de.zMult(Aout_ne, null, 1, 0, false, true); // traffic of demand d that leaves node n
if (A_dn.size() > 0) if (A_dn.getMaxLocation()[0] > 1 + Configuration.precisionFactor)
throw new Net2PlanException("The sum of the splitting factors of the output links of a node cannot exceed one");
IntArrayList ds = new IntArrayList();
IntArrayList es = new IntArrayList();
DoubleArrayList splits = new DoubleArrayList();
f_de.getNonZeros(ds, es, splits);
Map<Demand,Map<Link,Double>> newFrs = new HashMap<> ();
for (int cont = 0; cont < ds.size() ; cont ++)
{
final Demand demand = layer.demands.get(ds.get(cont));
final Link link = layer.links.get(es.get(cont));
final double splittingFactor = splits.get(cont);
if (splittingFactor < Configuration.precisionFactor) continue;
if (splittingFactor > 1 || splittingFactor < 0) throw new Net2PlanException ("Split factors must be between 0 and 1");
Map<Link,Double> frMap = newFrs.get(demand);
if (frMap == null) { frMap = new HashMap <> (); newFrs.put(demand, frMap); }
frMap.put(link, splittingFactor);
}
for (Demand d : layer.demands)
d.updateHopByHopRoutingToGivenFrs(newFrs.containsKey(d)? newFrs.get(d) : new HashMap<> ());
if (ErrorHandling.isDebugEnabled()) this.checkCachesConsistency();
}
示例6: readDemandSetFromFile
import cern.colt.list.tdouble.DoubleArrayList; //導入依賴的package包/類
@Override
public NetPlan readDemandSetFromFile(File file)
{
int N = -1;
DoubleMatrix2D trafficMatrix = null;
int currentRow = 0;
try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)))
{
String line;
while ((line = in.readLine()) != null)
{
line = line.trim();
if (line.isEmpty() || line.startsWith("//")) continue;
if (N == -1)
{
N = Integer.parseInt(line);
if (N <= 1) throw new Net2PlanException("Bad - Number of nodes must be greater than one");
trafficMatrix = DoubleFactory2D.dense.make(N, N);
}
else
{
DoubleArrayList aux = new DoubleArrayList();
StringTokenizer tokenizer = new StringTokenizer(line, " \t");
while (tokenizer.hasMoreTokens())
aux.add(Double.parseDouble(tokenizer.nextToken()));
aux.trimToSize();
if (aux.size() != N) throw new Net2PlanException("Offered traffic for node " + currentRow + " does not match the number of nodes");
trafficMatrix.viewRow(currentRow++).assign(aux.elements());
if (currentRow == N) break;
}
}
}
catch (Throwable e)
{
throw new RuntimeException(e);
}
if (N == -1 || currentRow != N) throw new Net2PlanException("Bad - Wrong format");
NetPlan netPlan = new NetPlan();
netPlan.setTrafficMatrix(trafficMatrix);
return netPlan;
}