public void run() { for (int c = firstColumn; c < lastColumn; c++) { AA.viewColumn(c).assign(x, DoubleFunctions.mult); } } });
public void run() { for (int c = firstColumn; c < lastColumn; c++) { AA.viewColumn(c).assign(x, DoubleFunctions.mult); } } });
/** * Returns the one-norm of matrix <tt>A</tt>, which is the maximum absolute * column sum. */ public double norm1(DoubleMatrix2D A) { double max = 0; for (int column = A.columns(); --column >= 0;) { max = Math.max(max, norm1(A.viewColumn(column))); } return max; }
private void checksInitialize() { /* Check in h_ct, the columns sum zero */ for (int t = 0; t < this.currentNetPlan.getNumberOfNodes(); t++) if (Math.abs(global_h_ct.viewColumn(t).zSum()) > PRECISIONFACTOR) throw new RuntimeException("Bad"); /* Check in h_nt, the columns sum zero */ for (int t = 0; t < this.currentNetPlan.getNumberOfNodes(); t++) if (Math.abs(global_h_nt.viewColumn(t).zSum()) > PRECISIONFACTOR) throw new RuntimeException("Bad"); }
/** * Returns the one-norm of matrix <tt>A</tt>, which is the maximum absolute * column sum. */ public double norm1(DoubleMatrix2D A) { double max = 0; for (int column = A.columns(); --column >= 0;) { max = Math.max(max, norm1(A.viewColumn(column))); } return max; }
/** * A matrix <tt>A</tt> is <i>diagonally dominant by column</i> if the * absolute value of each diagonal element is larger than the sum of the * absolute values of the off-diagonal elements in the corresponding column. * * <tt>returns true if for all i: abs(A[i,i]) > Sum(abs(A[j,i])); j != i.</tt> * Matrix may but need not be square. * <p> * Note: Ignores tolerance. */ public boolean isDiagonallyDominantByColumn(DoubleMatrix2D A) { cern.jet.math.tdouble.DoubleFunctions F = cern.jet.math.tdouble.DoubleFunctions.functions; int min = Math.min(A.rows(), A.columns()); for (int i = min; --i >= 0;) { double diag = Math.abs(A.getQuick(i, i)); diag += diag; if (diag <= A.viewColumn(i).aggregate(DoubleFunctions.plus, DoubleFunctions.abs)) return false; } return true; }
/** * A matrix <tt>A</tt> is <i>diagonally dominant by column</i> if the * absolute value of each diagonal element is larger than the sum of the * absolute values of the off-diagonal elements in the corresponding column. * * <tt>returns true if for all i: abs(A[i,i]) > Sum(abs(A[j,i])); j != i.</tt> * Matrix may but need not be square. * <p> * Note: Ignores tolerance. */ public boolean isDiagonallyDominantByColumn(DoubleMatrix2D A) { cern.jet.math.tdouble.DoubleFunctions F = cern.jet.math.tdouble.DoubleFunctions.functions; int min = Math.min(A.rows(), A.columns()); for (int i = min; --i >= 0;) { double diag = Math.abs(A.getQuick(i, i)); diag += diag; if (diag <= A.viewColumn(i).aggregate(DoubleFunctions.plus, DoubleFunctions.abs)) return false; } return true; }
/** * * @param x * @return */ public static IntMatrix1D any(DoubleMatrix2D x) { int cols = x.columns(); IntMatrix1D y = IntFactory1D.dense.make(cols); for (int i = 0; i < cols; i++) { int a = any(x.viewColumn(i)) ? 1 : 0; y.set(i, a); } return y; }
/** * * @param x * @return */ public static IntMatrix1D any(DoubleMatrix2D x) { int cols = x.columns(); IntMatrix1D y = IntFactory1D.dense.make(cols); for (int i = 0; i < cols; i++) { int a = any(x.viewColumn(i)) ? 1 : 0; y.set(i, a); } return y; }
/** * * @param x * @return */ public static IntMatrix1D any(DoubleMatrix2D x) { int cols = x.columns(); IntMatrix1D y = IntFactory1D.dense.make(cols); for (int i = 0; i < cols; i++) { int a = any(x.viewColumn(i)) ? 1 : 0; y.set(i, a); } return y; }
/** * Modifies the given matrix square matrix <tt>A</tt> such that it is * diagonally dominant by row and column, hence non-singular, hence * invertible. For testing purposes only. * * @param A * the square matrix to modify. * @throws IllegalArgumentException * if <tt>!isSquare(A)</tt>. */ public void generateNonSingular(DoubleMatrix2D A) { checkSquare(A); cern.jet.math.tdouble.DoubleFunctions F = cern.jet.math.tdouble.DoubleFunctions.functions; int min = Math.min(A.rows(), A.columns()); for (int i = min; --i >= 0;) { A.setQuick(i, i, 0); } for (int i = min; --i >= 0;) { double rowSum = A.viewRow(i).aggregate(DoubleFunctions.plus, DoubleFunctions.abs); double colSum = A.viewColumn(i).aggregate(DoubleFunctions.plus, DoubleFunctions.abs); A.setQuick(i, i, Math.max(rowSum, colSum) + i + 1); } }
/** * Modifies the given matrix square matrix <tt>A</tt> such that it is * diagonally dominant by row and column, hence non-singular, hence * invertible. For testing purposes only. * * @param A * the square matrix to modify. * @throws IllegalArgumentException * if <tt>!isSquare(A)</tt>. */ public void generateNonSingular(DoubleMatrix2D A) { checkSquare(A); cern.jet.math.tdouble.DoubleFunctions F = cern.jet.math.tdouble.DoubleFunctions.functions; int min = Math.min(A.rows(), A.columns()); for (int i = min; --i >= 0;) { A.setQuick(i, i, 0); } for (int i = min; --i >= 0;) { double rowSum = A.viewRow(i).aggregate(DoubleFunctions.plus, DoubleFunctions.abs); double colSum = A.viewColumn(i).aggregate(DoubleFunctions.plus, DoubleFunctions.abs); A.setQuick(i, i, Math.max(rowSum, colSum) + i + 1); } }
cols[i] = matrix.viewColumn(i);
A.assign(new cern.jet.random.tdouble.engine.DRand()); // initialize randomly double[] v1 = A.viewColumn(0).toArray(); double[] v2 = A.viewColumn(0).toArray(); System.out.print("now quick sorting... "); cern.colt.Timer timer = new cern.colt.Timer().start();
A.assign(new cern.jet.random.tdouble.engine.DRand()); // initialize randomly double[] v1 = A.viewColumn(0).toArray(); double[] v2 = A.viewColumn(0).toArray(); System.out.print("now quick sorting... "); cern.colt.Timer timer = new cern.colt.Timer().start();
/** * Normalizes the input traffic matrix with respect to a given incoming traffic vector. * * @param trafficMatrix Input traffic matrix * @param incomingTraffic Vector of incoming traffic to each node * @return Traffic matrix normalized to the specified incoming traffic per node */ public static DoubleMatrix2D normalizationPattern_incomingTraffic(DoubleMatrix2D trafficMatrix, double[] incomingTraffic) { checkTrafficMatrix(trafficMatrix); int N = trafficMatrix.rows(); if (incomingTraffic.length != N) throw new Net2PlanException("'incomingTraffic' size doesn't match the number of nodes"); DoubleMatrix2D trafficMatrix_out = trafficMatrix.copy(); for (int columnId = 0; columnId < N; columnId++) { DoubleMatrix1D column = trafficMatrix_out.viewColumn(columnId); double incomingTraffic_old = column.zSum(); if (incomingTraffic_old == 0) continue; column.assign(DoubleFunctions.mult(incomingTraffic[columnId] / incomingTraffic_old)); } return trafficMatrix_out; }
cern.colt.list.tdouble.DoubleArrayList values = new cern.colt.list.tdouble.DoubleArrayList(elements); for (int column = matrix.columns(); --column >= 0;) { matrix.viewColumn(column).toArray(elements); // copy column into
private static void checkSolution(NetPlan netPlan, DoubleMatrix2D xx_de , DoubleMatrix3D xx_des) { if (!netPlan.getLinksOversubscribed().isEmpty()) throw new Net2PlanException("Bad - Some link is oversubscribed (constraint violated)"); if (!netPlan.getDemandsBlocked().isEmpty()) throw new Net2PlanException("Bad - Some demand is blocked (constraint violated)"); for (SharedRiskGroup srg : netPlan.getSRGs()) { NetPlan npThis = netPlan.copy (); npThis.removeAllUnicastRoutingInformation(); DoubleMatrix2D this_xxde = xx_des.viewColumn (srg.getIndex ()).copy (); for (Link e : srg.getAffectedLinksAllLayers()) if (this_xxde.viewColumn(e.getIndex ()).zSum () != 0) throw new Net2PlanException("Bad - some failing links carry traffic"); npThis.setRoutingFromDemandLinkCarriedTraffic(this_xxde , true , false , null); if (!npThis.getLinksOversubscribed().isEmpty()) throw new Net2PlanException("Bad - Some link is oversubscribed (constraint violated) in a failure"); if (!npThis.getDemandsBlocked().isEmpty()) throw new Net2PlanException("Bad - Some demand is blocked (constraint violated) in a failure"); for (Demand d : netPlan.getDemands ()) { IntArrayList es_noFailure = new IntArrayList (); xx_de.viewRow (d.getIndex ()).getNonZeros(es_noFailure , new DoubleArrayList ()); boolean affectedByThisFailure = false; for (Link e : srg.getAffectedLinksAllLayers()) if (xx_de.get(d.getIndex() , e.getIndex ()) != 0) { affectedByThisFailure = true; break; } if (!affectedByThisFailure) { IntArrayList es_thisFailure = new IntArrayList (); this_xxde.viewRow (d.getIndex ()).getNonZeros(es_thisFailure , new DoubleArrayList ()); if (!es_noFailure.equals(es_thisFailure)) throw new Net2PlanException("Routing cannot change when a demand is not affected by the failure"); } } } } }
DoubleMatrix2D matrix = make(r, ac + bc); matrix.viewPart(0, 0, r, ac).assign(A); matrix.viewColumn(ac).assign(b); return matrix;
DoubleMatrix2D matrix = make(r, ac + bc); matrix.viewPart(0, 0, r, ac).assign(A); matrix.viewColumn(ac).assign(b); return matrix;