/**
*
*/
package vroom.optimization.online.jmsa.benchmarking;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import vroom.common.modeling.io.NovoaPersistenceHelper.DemandDistribution;
import vroom.common.utilities.logging.LoggerHelper;
import vroom.optimization.pl.symphony.vrp.CVRPSymphonySolver;
import vroom.optimization.vrph.VRPHSolver;
/**
* <code>PerfectInformationSolverTest</code>
* <p>
* Creation date: Oct 12, 2010 - 9:56:42 AM
*
* @author Victor Pillac, <a href="http://uniandes.edu.co">Universidad de Los Andes</a>-<a
* href="http://copa.uniandes.edu.co">Copa</a> <a href="http://www.emn.fr">Ecole des Mines de Nantes</a>-<a
* href="http://www.irccyn.ec-nantes.fr/irccyn/d/en/equipes/Slp">SLP</a>
* @version 1.0
*/
public class PerfectInformationSolverTest {
private PerfectInformationSolver piSolver;
private static DemandDistribution sDist = DemandDistribution.UNIFORM;
@BeforeClass
public static void setupClass() {
LoggerHelper.setupRootLogger(LoggerHelper.LEVEL_WARN, LoggerHelper.LEVEL_WARN, false);
}
@Before
public void setup() {
piSolver = new PerfectInformationSolver();
}
/**
* Test if the stored information is coherent with the instances generated by the {@link NovoaRun} class
*/
@org.junit.Test
public void checkCoherency() {
int[] sizes = { 60 };
int[] caps = { 1 };
int it = 0;
for (int size : sizes) {
for (int rep = 1; rep <= 5; rep++) {
for (int cap : caps) {
for (int run = 0; run < 100; run++) {
System.out.printf("[i_%sr%s_%s %s]", size, rep, cap, run);
double oldObj = piSolver.solvePerfectInformation(run, size, rep, cap, 1, 60000, false, false,
sDist);
double obj = piSolver
.solvePerfectInformation(run, size, rep, cap, 1, 60000, true, false, sDist);
System.out.printf(" - %s : stored:%s calculated:%s\n", Math.abs(oldObj - obj) < 1e-6 ? "OK"
: "FAILED", oldObj, obj);
Assert.assertEquals(String.format(
"[i_%sr%s_%s %s] Difference in objectives - stored:%s new:%s\n", size, rep, cap, run,
oldObj, obj), oldObj, obj, 1e-6);
it++;
if (it % 10 == 0) {
Runtime.getRuntime().gc();
}
}
System.out.printf("[i_%sr%s_%s] OK\n", size, rep, cap);
}
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
LoggerHelper.setupRootLogger(LoggerHelper.LEVEL_WARN, LoggerHelper.LEVEL_WARN, false);
CVRPSymphonySolver.LOGGER.setLevel(LoggerHelper.LEVEL_INFO);
VRPHSolver.LOGGER.setLevel(LoggerHelper.LEVEL_INFO);
setupClass();
PerfectInformationSolverTest test = new PerfectInformationSolverTest();
test.setup();
// double val = test.piSolver.solvePerfectInformation(76, 60, 2,
// NovoaPersistenceHelper.getCapacityIdx(60, 1, 175), 1, Integer.MAX_VALUE, true, false);
//
// System.out.println(val);
test.checkCoherency();
System.exit(0);
}
}