Search in sources :

Example 1 with CloudBalance

use of org.kie.karaf.itest.planner.domain.CloudBalance in project droolsjbpm-integration by kiegroup.

the class PlannerCloudBalanceIntegrationTest method cloudBalanceGeneratorForFuse.

private CloudBalance cloudBalanceGeneratorForFuse(int computerNum, int processNum, int seed) {
    Random random = new Random(seed);
    int costRange = 10000;
    int costBaseline = 1000;
    int cpuPowerRange = 100;
    int cpuPowerBaseLine = 10;
    int memoryRange = 100;
    int memoryBaseLine = 10;
    int networkRange = 100;
    int networkBaseLine = 10;
    CloudBalance cloudBalance = new CloudBalance();
    String string = Integer.MIN_VALUE + "hard";
    string += "/";
    string += Integer.MIN_VALUE + "soft";
    cloudBalance.setScore(HardSoftScore.parseScore(string));
    List<CloudComputer> computerList = new ArrayList<>();
    for (int i = 0; i < computerNum; i++) {
        CloudComputer computer = new CloudComputer();
        computer.setCost(random.nextInt(costRange) + costBaseline);
        computer.setCpuPower(random.nextInt(cpuPowerRange) + cpuPowerBaseLine);
        computer.setMemory(random.nextInt(memoryRange) + memoryBaseLine);
        computer.setNetworkBandwidth(random.nextInt(networkRange) + networkBaseLine);
        computerList.add(computer);
    }
    int processCpuPowerRange = 50;
    int processCpuPowerBaseLine = 1;
    int processMemoryRange = 50;
    int processMemoryBaseLine = 1;
    int processNetworkRange = 50;
    int processNetworkBaseLine = 1;
    List<CloudProcess> processList = new ArrayList<>();
    for (int i = 0; i < processNum; i++) {
        CloudProcess process = new CloudProcess();
        process.setRequiredCpuPower(random.nextInt(processCpuPowerRange) + processCpuPowerBaseLine);
        process.setRequiredMemory(random.nextInt(processMemoryRange) + processMemoryBaseLine);
        process.setRequiredNetworkBandwidth(random.nextInt(processNetworkRange) + processNetworkBaseLine);
        processList.add(process);
    }
    cloudBalance.setComputerList(computerList);
    cloudBalance.setProcessList(processList);
    return cloudBalance;
}
Also used : Random(java.util.Random) CloudComputer(org.kie.karaf.itest.planner.domain.CloudComputer) CloudBalance(org.kie.karaf.itest.planner.domain.CloudBalance) ArrayList(java.util.ArrayList) CloudProcess(org.kie.karaf.itest.planner.domain.CloudProcess)

Example 2 with CloudBalance

use of org.kie.karaf.itest.planner.domain.CloudBalance in project droolsjbpm-integration by kiegroup.

the class PlannerCloudBalanceIntegrationTest method solveUsingSolverFactory.

private void solveUsingSolverFactory(String configFile) {
    SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource(configFile, PlannerCloudBalanceIntegrationTest.class.getClassLoader());
    CloudBalance cloudBalance = cloudBalanceGeneratorForFuse(10, 20, 0);
    Assert.assertEquals(cloudBalance.getScore().getHardScore(), Integer.MIN_VALUE);
    Assert.assertEquals(cloudBalance.getScore().getSoftScore(), Integer.MIN_VALUE);
    Solver<CloudBalance> solver = solverFactory.buildSolver();
    solver.solve(cloudBalance);
    CloudBalance solution = solver.getBestSolution();
    Assert.assertNotEquals(solution.getScore().getHardScore(), Integer.MIN_VALUE);
    Assert.assertNotEquals(solution.getScore().getSoftScore(), Integer.MIN_VALUE);
}
Also used : CloudBalance(org.kie.karaf.itest.planner.domain.CloudBalance)

Example 3 with CloudBalance

use of org.kie.karaf.itest.planner.domain.CloudBalance in project droolsjbpm-integration by kiegroup.

the class PlannerCloudBalanceIntegrationTest method solveSolution.

private void solveSolution(CloudBalance cloudBalance) {
    LocalSearchPhaseConfig localSearchPhaseConfig = new LocalSearchPhaseConfig();
    localSearchPhaseConfig.setTerminationConfig(new TerminationConfig().withStepCountLimit(20));
    SolverConfig config = new SolverConfig().withEntityClassList(Arrays.asList(CloudProcess.class)).withSolutionClass(CloudBalance.class).withScoreDirectorFactory(new ScoreDirectorFactoryConfig().withIncrementalScoreCalculatorClass(CloudBalancingIncrementalScoreCalculator.class)).withPhases(new ConstructionHeuristicPhaseConfig().withConstructionHeuristicType(ConstructionHeuristicType.FIRST_FIT_DECREASING), localSearchPhaseConfig);
    Assert.assertEquals(cloudBalance.getScore().getHardScore(), Integer.MIN_VALUE);
    Assert.assertEquals(cloudBalance.getScore().getSoftScore(), Integer.MIN_VALUE);
    SolverFactory<CloudBalance> solverFactory = SolverFactory.create(config);
    Solver<CloudBalance> solver = solverFactory.buildSolver();
    solver.solve(cloudBalance);
    CloudBalance solution = solver.getBestSolution();
    Assert.assertNotEquals(solution.getScore().getHardScore(), Integer.MIN_VALUE);
    Assert.assertNotEquals(solution.getScore().getSoftScore(), Integer.MIN_VALUE);
}
Also used : ScoreDirectorFactoryConfig(org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig) TerminationConfig(org.optaplanner.core.config.solver.termination.TerminationConfig) CloudBalance(org.kie.karaf.itest.planner.domain.CloudBalance) LocalSearchPhaseConfig(org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig) ConstructionHeuristicPhaseConfig(org.optaplanner.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig) SolverConfig(org.optaplanner.core.config.solver.SolverConfig)

Aggregations

CloudBalance (org.kie.karaf.itest.planner.domain.CloudBalance)3 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 CloudComputer (org.kie.karaf.itest.planner.domain.CloudComputer)1 CloudProcess (org.kie.karaf.itest.planner.domain.CloudProcess)1 ConstructionHeuristicPhaseConfig (org.optaplanner.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig)1 LocalSearchPhaseConfig (org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig)1 ScoreDirectorFactoryConfig (org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig)1 SolverConfig (org.optaplanner.core.config.solver.SolverConfig)1 TerminationConfig (org.optaplanner.core.config.solver.termination.TerminationConfig)1