/*
 * LVtests.java
 *
 * Created on August 13, 2004, 12:56 PM
 * Last Updated on August 26, 2004
 */

package LotkaVolterra;

import java.io.*;

public final class LVtests {
    
    /** Creates a new instance of LVtests */
    private LVtests() {}
    
    // type = 0 means this is LE vs % moved links
    // type = 1 means this is LE vs % deleted links
    public static void LEvsP(int type, Animal[] template, double pStart, double pEnd, double stepSize, int samplesPerStep, int timeUnits, double dt, String saveFileName) { 
        
        try {
            PrintWriter fileOut = new PrintWriter(new FileWriter(new File(saveFileName)));
            if (type == 0) {
                fileOut.println("LE vs % moved links");
            } else {
                fileOut.println("LE vs % deleted links");
            }
            
            String temp = "";

            Animal[] animal;
            double LE;

            System.out.print("At p = ");
            for(double p = pStart; p <= pEnd + 0.00000001; p = p + stepSize) {
                
                System.out.print(p + "...");
                temp = p + ";";

                for (int i = 0; i < samplesPerStep; i++) {
                    
                    System.out.print(i + ", ");
                    
                    
                    do {
                        
                        // either move links, or delete links
                        if (type == 0) {
                            animal = LVroutines.createAnimals(template, p);
                        } else {
                            animal = LVroutines.deleteConnections(template, p);
                        }

                        // Evolve thru time to get back onto the attractor 
                        // and to make sure no species die
                        LVroutines.randomizePopulations(animal);
                        LVroutines.evolveThruTime(animal, 5000, dt);
                    
                    } while (LVroutines.noneDead(animal) == false);

                    LE = LVroutines.calculateLE(animal, timeUnits, dt);
                    temp = temp + LE + ";";

                }  // end of i loop

                fileOut.println(temp);
                System.out.print("\n");
 
            }  // end of p loop

            fileOut.close();
        
        } catch (Exception e) {
            System.out.println("Error Writing File!");
        }
        
    }  // end of LEvsP method
    
    
}  // End of LVtests class
