Example usage for org.apache.commons.math3.linear Array2DRowRealMatrix getEntry

List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix getEntry

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear Array2DRowRealMatrix getEntry.

Prototype

@Override
public double getEntry(final int row, final int column) throws OutOfRangeException 

Source Link

Usage

From source file:lanchester.MultiArena.java

public void step() {
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);//from   www  . j  a va 2s .  co  m
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    //        for(int i1=0;i1<eVals.length;i1++){
    //            System.out.println("eVals["+i1+"] = "+eVals[i1]);
    //        }
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            AthenaForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getForceSize() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    MultiTimeStep currentStep = new MultiTimeStep(numFoes);
    currentTime += timeStep;
    currentStep.setTime(currentTime);
    for (int i1 = 0; i1 < numFoes; i1++) {
        double updatedForce = 0.;
        for (int i2 = 0; i2 < numFoes; i2++) {
            updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
            //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
            //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
        }
        forces.get(i1).updateForce(updatedForce);
        currentStep.setForceNumber(updatedForce, i1);
    }
    history.add(currentStep);
    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (true) {
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.MultiArena2.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);//from   ww  w  .ja  v  a2 s.co  m
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    //        for(int i1=0;i1<eVals.length;i1++){
    //            System.out.println("eVals["+i1+"] = "+eVals[i1]);
    //        }
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            AthenaForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getForceSize() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    int cntr = 0;
    int numGone;
    do {
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            if (forces.get(i1).getForceSize() > lb) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);
                    if (updatedForce < 1.) {
                        updatedForce = 0.;
                        numGone++;
                    }
                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
            } else {
                updatedForce = lb / 2.;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        cntr++;
    } while (aboveFloor && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setFloor(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.MultiArena3.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 100.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);/*from w  w w  .  jav  a 2 s .  co m*/
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            MultiForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);
                }
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                numGone++;
                updatedForce = lb;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setFloor(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.MultiArena4.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    //                        setStances(i1,i2);
                    setFloor(i1, i2);//  w w w  . j  a v  a2 s. co m
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            MultiForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            //                if (forces.get(i1).getForceSize() > lb) {
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);

                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                updatedForce = lb;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
            //                for (int i2 = 0; i2 < numFoes; i1++) {
            //                    if (i1 != i2) {
            //
            //                    }
            //                }
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.SimpleMultiArena.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    //                        setStances(i1,i2);
                    setFloor(i1, i2);/*  w ww  .jav  a 2 s .c  o  m*/
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    //        EigenDecomposition eigen = new EigenDecomposition(mat);
    //        double det = eigen.getDeterminant();
    //        double[] eVals = eigen.getRealEigenvalues();
    //        if (eigen.hasComplexEigenvalues()) {
    //            System.out.println("Complex eigenvalues");
    //            for (int i1 = 0; i1 < forces.size(); i1++) {
    //                MultiForce f = forces.get(i1);
    //                System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
    //            }
    //        }
    //        double[] initialNums = getInitialNumbers(forces);
    //        Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    //        LUDecomposition lu = new LUDecomposition(eVectors);
    //        double det2 = lu.getDeterminant();
    //        double[] coeffs = new double[numFoes];
    //        for (int i1 = 0; i1 < numFoes; i1++) {
    //            Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
    //            tmpMat.setColumn(i1, initialNums);
    //            LUDecomposition tmpLU = new LUDecomposition(tmpMat);
    //            double tmpDet = tmpLU.getDeterminant();
    //            coeffs[i1] = tmpDet / det2;
    //        }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        double[] initialNums = getInitialNumbers(forces);

        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            //                if (forces.get(i1).getForceSize() > lb) {
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += initialNums[i2] * mat.getEntry(i1, i2) * timeStep;

                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
                updatedForce += initialNums[i1];
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                updatedForce = lb;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
            //                for (int i2 = 0; i2 < numFoes; i1++) {
            //                    if (i1 != i2) {
            //
            //                    }
            //                }
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:net2.N2MultiArena.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    System.out.println("Num foes = " + numFoes);
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);//  w ww . j  a  v  a2 s . c  om
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            N2ForceUnit f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    //        int cntr = 0;
    int numGone;
    //        do {
    timeStep = determineTimeStep();
    MultiTimeStep currentStep = new MultiTimeStep(numFoes);
    currentTime += timeStep;
    currentCycle += timeStep;
    currentStep.setTime(currentTime);
    numGone = 0;
    for (int i1 = 0; i1 < numFoes; i1++) {
        double updatedForce = 0.;
        //                if (forces.get(i1).getForceSize() > lb) {
        if (stillAlive[i1]) {
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);

            }
            if (updatedForce < 1.) {
                updatedForce = lb;
                stillAlive[i1] = false;
                numGone++;
            }
        } else {
            updatedForce = lb;
            numGone++;
        }
        forces.get(i1).updateForce(updatedForce);
        currentStep.setForceNumber(updatedForce, i1);
    }
    history.add(currentStep);
    aboveFloor = checkAboveFloors();
    belowCeiling = checkBelowCeilings();
    //            cntr++;
    //        } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:net2.N2MultiArena.java

public double[] project(double deltaT, double[] coeffs, double[] eVals, Array2DRowRealMatrix eVects) {
    int numFoes = coeffs.length;
    double[] updated = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        double updatedForce = 0.;
        if (forces.get(i1).getNumber() > lb) {
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                updatedForce += coeffs[i2] * eVects.getEntry(i1, i2) * Math.exp(eVals[i2] * deltaT);
                if (updatedForce < 1.) {
                    updatedForce = 0.;//from   w  w  w . j av a  2s  .  com
                    //                            numGone++;
                }
            }
        } else {
            updatedForce = lb / 2.;
            //                    numGone++;
        }
        updated[i1] = updatedForce;
    }
    return updated;
}

From source file:net2.N2SimpleMultiArena.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = N2Constants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    //                        setStances(i1,i2);
                    setFloor(i1, i2);//from w  ww .java 2s. c  om
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    //        EigenDecomposition eigen = new EigenDecomposition(mat);
    //        double det = eigen.getDeterminant();
    //        double[] eVals = eigen.getRealEigenvalues();
    //        if (eigen.hasComplexEigenvalues()) {
    //            System.out.println("Complex eigenvalues");
    //            for (int i1 = 0; i1 < forces.size(); i1++) {
    //                MultiForce f = forces.get(i1);
    //                System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
    //            }
    //        }
    //        double[] initialNums = getInitialNumbers(forces);
    //        Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    //        LUDecomposition lu = new LUDecomposition(eVectors);
    //        double det2 = lu.getDeterminant();
    //        double[] coeffs = new double[numFoes];
    //        for (int i1 = 0; i1 < numFoes; i1++) {
    //            Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
    //            tmpMat.setColumn(i1, initialNums);
    //            LUDecomposition tmpLU = new LUDecomposition(tmpMat);
    //            double tmpDet = tmpLU.getDeterminant();
    //            coeffs[i1] = tmpDet / det2;
    //        }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        N2MultiTimeStep currentStep = new N2MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        double[] initialNums = getInitialNumbers(forces);

        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            //                if (forces.get(i1).getForceSize() > lb) {
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += initialNums[i2] * mat.getEntry(i1, i2) * timeStep;

                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
                updatedForce += initialNums[i1];
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                updatedForce = lb;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
            //                for (int i2 = 0; i2 < numFoes; i1++) {
            //                    if (i1 != i2) {
            //
            //                    }
            //                }
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = N2Constants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:org.mpetnuch.gauss.linearalgebra.blas3.JBlasLevel3Test.java

@Test
public void testDgemm() {
    final DenseMatrix a = DenseMatrix.from(generateData(M, P));
    final DenseMatrix b = DenseMatrix.from(generateData(P, N));

    final Array2DRowRealMatrix aa = new Array2DRowRealMatrix(generateData(M, P));
    final Array2DRowRealMatrix bb = new Array2DRowRealMatrix(generateData(P, N));

    final DenseMatrix c = a.multiply(b);
    final Array2DRowRealMatrix cc = aa.multiply(bb);

    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            Assert.assertEquals(c.get(i, j), cc.getEntry(i, j), 1.0e-6);
        }//from  www .  j  a va2  s .  c o m
    }
}

From source file:org.orekit.files.ccsds.OEMParserTest.java

@Test
public void testParseOEM1() throws OrekitException, IOException {
    ////w w  w  .  j  av a  2s.  c o m
    final String ex = "/ccsds/OEMExample.txt";
    final InputStream inEntry = getClass().getResourceAsStream(ex);
    final OEMParser parser = new OEMParser().withMu(CelestialBodyFactory.getEarth().getGM());
    final OEMFile file = parser.parse(inEntry, "OEMExample.txt");
    Assert.assertEquals(TimeSystem.UTC, file.getTimeSystem());
    Assert.assertEquals("MARS GLOBAL SURVEYOR",
            file.getEphemeridesBlocks().get(0).getMetaData().getObjectName());
    Assert.assertEquals("1996-062A", file.getEphemeridesBlocks().get(0).getMetaData().getObjectID());
    Assert.assertEquals("MARS BARYCENTER", file.getEphemeridesBlocks().get(0).getMetaData().getCenterName());
    Assert.assertEquals(1996, file.getEphemeridesBlocks().get(0).getMetaData().getLaunchYear());
    Assert.assertEquals(62, file.getEphemeridesBlocks().get(0).getMetaData().getLaunchNumber());
    Assert.assertEquals("A", file.getEphemeridesBlocks().get(0).getMetaData().getLaunchPiece());
    Assert.assertFalse(file.getEphemeridesBlocks().get(0).getMetaData().getHasCreatableBody());
    Assert.assertNull(file.getEphemeridesBlocks().get(0).getMetaData().getCenterBody());
    Assert.assertEquals(new AbsoluteDate(1996, 12, 18, 12, 00, 0.331, TimeScalesFactory.getUTC()),
            file.getEphemeridesBlocks().get(0).getStartTime());
    Assert.assertEquals(new AbsoluteDate(1996, 12, 28, 21, 28, 0.331, TimeScalesFactory.getUTC()),
            file.getEphemeridesBlocks().get(0).getStopTime());
    Assert.assertEquals(new AbsoluteDate(1996, 12, 18, 12, 10, 0.331, TimeScalesFactory.getUTC()),
            file.getEphemeridesBlocks().get(0).getUseableStartTime());
    Assert.assertEquals(new AbsoluteDate(1996, 12, 28, 21, 23, 0.331, TimeScalesFactory.getUTC()),
            file.getEphemeridesBlocks().get(0).getUseableStopTime());
    Assert.assertEquals("HERMITE", file.getEphemeridesBlocks().get(0).getInterpolationMethod());
    Assert.assertEquals(7, file.getEphemeridesBlocks().get(0).getInterpolationDegree());
    ArrayList<String> ephemeridesDataLinesComment = new ArrayList<String>();
    ephemeridesDataLinesComment.add("This file was produced by M.R. Somebody, MSOO NAV/JPL, 1996NOV 04. It is");
    ephemeridesDataLinesComment.add("to be used for DSN scheduling purposes only.");
    Assert.assertEquals(ephemeridesDataLinesComment,
            file.getEphemeridesBlocks().get(0).getEphemeridesDataLinesComment());
    CartesianOrbit orbit = new CartesianOrbit(
            new PVCoordinates(new Vector3D(2789.619 * 1000, -280.045 * 1000, -1746.755 * 1000),
                    new Vector3D(4.73372 * 1000, -2.49586 * 1000, -1.04195 * 1000)),
            FramesFactory.getEME2000(), new AbsoluteDate("1996-12-18T12:00:00.331", TimeScalesFactory.getUTC()),
            CelestialBodyFactory.getEarth().getGM());
    Assert.assertArrayEquals(
            orbit.getPVCoordinates().getPosition().toArray(), file.getEphemeridesBlocks().get(0)
                    .getEphemeridesDataLines().get(0).getOrbit().getPVCoordinates().getPosition().toArray(),
            1e-10);
    Assert.assertArrayEquals(
            orbit.getPVCoordinates().getVelocity().toArray(), file.getEphemeridesBlocks().get(0)
                    .getEphemeridesDataLines().get(0).getOrbit().getPVCoordinates().getVelocity().toArray(),
            1e-10);
    Assert.assertArrayEquals((new Vector3D(1, 1, 1)).toArray(),
            file.getEphemeridesBlocks().get(1).getEphemeridesDataLines().get(0).getAcceleration().toArray(),
            1e-10);
    final Array2DRowRealMatrix covMatrix = new Array2DRowRealMatrix(6, 6);
    final double[] column1 = { 3.331349476038534e-04, 4.618927349220216e-04, -3.070007847730449e-04,
            -3.349365033922630e-07, -2.211832501084875e-07, -3.041346050686871e-07 };
    final double[] column2 = { 4.618927349220216e-04, 6.782421679971363e-04, -4.221234189514228e-04,
            -4.686084221046758e-07, -2.864186892102733e-07, -4.989496988610662e-07 };
    final double[] column3 = { -3.070007847730449e-04, -4.221234189514228e-04, 3.231931992380369e-04,
            2.484949578400095e-07, 1.798098699846038e-07, 3.540310904497689e-07 };
    final double[] column4 = { -3.349365033922630e-07, -4.686084221046758e-07, 2.484949578400095e-07,
            4.296022805587290e-10, 2.608899201686016e-10, 1.869263192954590e-10 };
    final double[] column5 = { -2.211832501084875e-07, -2.864186892102733e-07, 1.798098699846038e-07,
            2.608899201686016e-10, 1.767514756338532e-10, 1.008862586240695e-10 };
    final double[] column6 = { -3.041346050686871e-07, -4.989496988610662e-07, 3.540310904497689e-07,
            1.869263192954590e-10, 1.008862586240695e-10, 6.224444338635500e-10 };
    covMatrix.setColumn(0, column1);
    covMatrix.setColumn(1, column2);
    covMatrix.setColumn(2, column3);
    covMatrix.setColumn(3, column4);
    covMatrix.setColumn(4, column5);
    covMatrix.setColumn(5, column6);
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 6; j++) {
            Assert.assertEquals(covMatrix.getEntry(i, j), file.getEphemeridesBlocks().get(2)
                    .getCovarianceMatrices().get(0).getMatrix().getEntry(i, j), 1e-10);
        }
    }
    Assert.assertEquals(new AbsoluteDate("1996-12-28T21:29:07.267", TimeScalesFactory.getUTC()),
            file.getEphemeridesBlocks().get(2).getCovarianceMatrices().get(0).getEpoch());
    Assert.assertEquals(FramesFactory.getEME2000(),
            file.getEphemeridesBlocks().get(2).getCovarianceMatrices().get(1).getFrame());
}