// Path to the configuration file
String path = "c:\\config.xml";
// Switch between Dynamic Programming and Moving Average algorithm
boolean dynProg = true;
// Velocity and road slope discretization interval in meters
double discrInt = 20;
// Horizon within the energy will be optimized
int horizon = 50;
      
// Road Slope of the driving cycle in radians
double[] roadSlope = {0,-0.0076,-0.0089,-0.0101,-0.0147,-0.0113, ...};
// Velocity profile in m/s.
double[] velocity = {0,1.6250,3.9750,6.0000,7.7000,6.8000, ...};

// Interface
IEV myCycle;

try 
{
    if (dynProg) 
        myCycle = EVDP.getInstance(path);
    else
        myCycle = EVMA.getInstance(path);         
         
    myCycle.setBatteryInitSoc(30);
    myCycle.setScInitSoc(100);
    myCycle.setProfileVelocitySlope(velocity,roadSlope,discrInt,horizon);
    
    // If we use Dynamic programming, set grid discretization to 10 kw
    // (default value is 30 kW)
    if (myCycle instanceof EVDP)
        ((EVDP) myCycle).setPowerDiscretization(10);
         
    // Prints parameters
    myCycle.getInfo();
         
    if (myCycle instanceof EVDP) System.out.println("Dymanic Programming algorithm");
    else System.out.println("Moving Average algorithm");
         
    // Make energy optimization and get the final battery SoC value
    double socBf = myCycle.optimizeEnergy();
    // Get optimal Power-Split-Ratio values for whole cycle
    double[] psr = myCycle.getOptPsr();  
    System.out.format("Final SoC is %7.4f %%. %n", socBf);

} 
catch (Exception e) 
{
    e.printStackTrace();
} 
