List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix scalarMultiply
public RealMatrix scalarMultiply(final double d)
From source file:org.interpss.opf.dc.impl.EqIneqMatrixBuilder.java
private Array2DRowRealMatrix formAngleDiffWeightMatrix() { int numOfBus = opfNet.getNoActiveBus(); Array2DRowRealMatrix angleDiffWeight = new Array2DRowRealMatrix(numOfBus, numOfBus); for (Bus busi : opfNet.getBusList()) { //double ADWij = 0; //double ADWii = 0; int i = busi.getSortNumber(); for (Branch bra : busi.getFromBranchList()) { Bus busj = bra.getToBus();/*ww w.jav a 2 s . com*/ int j = busj.getSortNumber(); double ADWij = -1; //ADWii++; angleDiffWeight.setEntry(i, j, ADWij); angleDiffWeight.setEntry(j, i, ADWij); } angleDiffWeight.setEntry(i, i, busi.getBranchList().size()); } return (Array2DRowRealMatrix) angleDiffWeight.scalarMultiply(2 * opfNet.getAnglePenaltyFactor()); }
From source file:org.interpss.opf.dc.impl.EqIneqMatrixBuilder.java
public Array2DRowRealMatrix formCeq() { int numOfBus = opfNet.getNoActiveBus(); int numOfGen = opfNet.getNoOfGen(); Array2DRowRealMatrix genBusAdjacent = new Array2DRowRealMatrix(numOfBus, numOfGen); int genCount = 0; for (Bus b : opfNet.getBusList()) { // set the elements in genBusAdjacent matrix to ONE if there is a // generator ; /*/*from w w w .j a va 2s. co m*/ * in the case of multi-gen ,all are treated as a union; * not suitable for a case with multi-generators connected to one * bus; */ if (opfNet.isOpfGenBus(b)) { genBusAdjacent.setEntry(b.getSortNumber(), genCount, 1); genCount++; } } Array2DRowRealMatrix BrTranspose = (Array2DRowRealMatrix) this.getReducedBusAdmittance().transpose(); Array2DRowRealMatrix CeqTranspose = new Array2DRowRealMatrix(numOfBus, numOfBus + numOfGen - 1); CeqTranspose.setSubMatrix(genBusAdjacent.getData(), 0, 0); // Ceq'={genBusAdjacent,BrTranspose} CeqTranspose.setSubMatrix(BrTranspose.scalarMultiply(-1).getData(), 0, numOfGen); return (Array2DRowRealMatrix) CeqTranspose.transpose(); }
From source file:org.interpss.opf.dc.impl.EqIneqMatrixBuilder.java
public Array2DRowRealMatrix formCiq() { int numOfBranch = opfNet.getNoActiveBranch(); int numOfBus = opfNet.getNoActiveBus(); int numOfGen = opfNet.getNoOfGen(); double bij = DEFAULT_BIJ; int braIndex = 0; Array2DRowRealMatrix braAdmDiag = new Array2DRowRealMatrix(numOfBranch, numOfBranch); Array2DRowRealMatrix braBusAdjacent = new Array2DRowRealMatrix(numOfBranch, numOfBus - 1); int swingIndex = this.getSwingBusIndex(); for (Branch bra : opfNet.getBranchList()) { //if (bra.isAclfBranch()) { DclfOpfBranch aclfBra = (DclfOpfBranch) bra; // create branch admittance matrix bij = (aclfBra.getZ().getImaginary() > 0.00001) ? 1 / aclfBra.getZ().getImaginary() : DEFAULT_BIJ; // in case x=0; braAdmDiag.setEntry(braIndex, braIndex, bij); // create branch-bus connected or adjacent matrix; if (!((DclfOpfBus) bra.getFromBus()).isSwing()) { int fromBusIndex = bra.getFromBus().getSortNumber(); fromBusIndex = (fromBusIndex < swingIndex) ? fromBusIndex : fromBusIndex - 1; // insure nonswing bus; braBusAdjacent.setEntry(braIndex, fromBusIndex, 1); }/*from ww w . ja v a2s . c o m*/ if (!((DclfOpfBus) bra.getToBus()).isSwing()) { int toBusIndex = bra.getToBus().getSortNumber(); toBusIndex = (toBusIndex < swingIndex) ? toBusIndex : toBusIndex - 1; braBusAdjacent.setEntry(braIndex, toBusIndex, -1); } braIndex++; //} } int genIndex = 0; Array2DRowRealMatrix eyeGenP = new Array2DRowRealMatrix(numOfGen, numOfGen); for (Bus bus : opfNet.getBusList()) { if (opfNet.isOpfGenBus(bus)) { eyeGenP.setEntry(genIndex, genIndex, 1); genIndex++; } } Array2DRowRealMatrix DAr = braAdmDiag.multiply(braBusAdjacent); // Ciq'={Ot,-braAdmDiag*braBusAdjacent; // -Ot,braAdmDiag*braBusAdjacent; // eyeGenP,Op; // -eyeGenP,-Op} Array2DRowRealMatrix CiqTranspose = new Array2DRowRealMatrix(numOfBranch * 2 + numOfGen * 2, numOfGen + numOfBus - 1); CiqTranspose.setSubMatrix(DAr.scalarMultiply(-1).getData(), 0, numOfGen); CiqTranspose.setSubMatrix(DAr.getData(), numOfBranch, numOfGen); CiqTranspose.setSubMatrix(eyeGenP.getData(), 2 * numOfBranch, 0); CiqTranspose.setSubMatrix(eyeGenP.scalarMultiply(-1).getData(), 2 * numOfBranch + numOfGen, 0); // Ciq=CiqTranspose' return (Array2DRowRealMatrix) CiqTranspose.transpose(); }
From source file:outlineDescriptor.ODUtils.java
/** * Generates a 2D covariance matrix for a distribution function * * @param vX X component//w w w . j av a2 s . c o m * @param vY Y component * @param eV1 First eigenvalue * @param eV2 Second eigenvalue * * @return Resulting covariance matrix */ public static Array2DRowRealMatrix getDistributionCovMatrix(double vX, double vY, double eV1, double eV2) { double multiplier = 1 / (vX * vX + vY * vY); Array2DRowRealMatrix vectMat = new Array2DRowRealMatrix(2, 2); Array2DRowRealMatrix valMat = new Array2DRowRealMatrix(2, 2); valMat.setEntry(0, 0, eV1); valMat.setEntry(1, 1, eV2); vectMat.setEntry(0, 0, vX); vectMat.setEntry(0, 1, vY); vectMat.setEntry(1, 0, -vY); vectMat.setEntry(1, 1, vX); Array2DRowRealMatrix vE = vectMat.multiply(valMat); Array2DRowRealMatrix tempCov = vE.multiply((Array2DRowRealMatrix) vectMat.transpose()); return (Array2DRowRealMatrix) tempCov.scalarMultiply(multiplier); }