package org.jboss.qa.brms.performance.examples.conferencescheduling;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Stream;

import org.jboss.qa.brms.performance.examples.AbstractExample;
import org.jboss.qa.brms.performance.examples.conferencescheduling.domain.ConferenceSolution;
import org.jboss.qa.brms.performance.examples.conferencescheduling.domain.Talk;
import org.jboss.qa.brms.performance.examples.conferencescheduling.persistence.ConferenceSchedulingGenerator;
import org.optaplanner.core.api.solver.SolverFactory;
import org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig;
import org.optaplanner.core.config.solver.SolverConfig;

public class ConferenceScheduling extends AbstractExample<ConferenceSolution> {

    private static final String PATH_TO_DRL_FILE = "/org/jboss/qa/brms/performance/examples/conferencescheduling/solver/conferenceSchedulingScoreRules.drl";
    private static final String PATH_TO_SOLVE_CONFIG = "/org/jboss/qa/brms/performance/examples/conferencescheduling/solver/conferenceSchedulingSolverConfig.xml";

    public enum DataSet {
        TALKS_36_TIMESLOTS_12_ROOMS_5("TIME_12;ROOM_5;SPEAKER_26;TALK_36"),
        TALKS_108_TIMESLOTS_18_ROOMS_10("TIME_18;ROOM_10;SPEAKER_74;TALK_108"),
        TALKS_216_TIMESLOTS_18_ROOMS_20("TIME_18;ROOM_20;SPEAKER_146;TALK_216");

        private int timeslotListSize;
        private int roomListSize;
        private int speakerListSize;
        private int talkListSize;

        DataSet(String generatorParameters) {
            Stream<String> parameters = Arrays.stream(generatorParameters.split(";", 4));

            parameters.forEach(s -> {
                if (s.startsWith("TIME")) {
                    timeslotListSize = Integer.parseInt(s.split("_")[1]);
                } else if (s.startsWith("ROOM")) {
                    roomListSize = Integer.parseInt(s.split("_")[1]);
                } else if (s.startsWith("SPEAKER")) {
                    speakerListSize = Integer.parseInt(s.split("_")[1]);
                } else if (s.startsWith("TALK")) {
                    talkListSize = Integer.parseInt(s.split("_")[1]);
                }
            });

            parameters.close();
        }

        public int getTimeslotListSize() {
            return timeslotListSize;
        }

        public int getRoomListSize() {
            return roomListSize;
        }

        public int getSpeakerListSize() {
            return speakerListSize;
        }

        public int getTalkListSize() {
            return talkListSize;
        }
    }

    public ConferenceSolution loadSolvingProblem(ConferenceScheduling.DataSet dataset) {
        return new ConferenceSchedulingGenerator().createConferenceSolution(dataset.timeslotListSize, dataset.roomListSize,
                                                                            dataset.speakerListSize, dataset.talkListSize);
    }

    @Override
    public ConferenceSolution loadSolvingProblem(File file) {
        throw new UnsupportedOperationException("Unsupported data set loading from file");
    }

    @Override
    public SolverFactory<ConferenceSolution> getDefaultSolverFactory() {
        return SolverFactory.createFromXmlInputStream(this.getClass().getResourceAsStream(PATH_TO_SOLVE_CONFIG));
    }

    @Override
    public SolverFactory<ConferenceSolution> getBaseSolverFactory() {
        SolverFactory<ConferenceSolution> solverFactory = SolverFactory.createEmpty();
        SolverConfig solverConfig = solverFactory.getSolverConfig();

        solverConfig.setSolutionClass(ConferenceSolution.class);
        solverConfig.setEntityClassList(Collections.singletonList(Talk.class));
        solverConfig.setScoreDirectorFactoryConfig(new ScoreDirectorFactoryConfig());
        solverConfig.getScoreDirectorFactoryConfig().setScoreDrlList(Collections.singletonList(PATH_TO_DRL_FILE));
        solverConfig.getScoreDirectorFactoryConfig().setInitializingScoreTrend("ONLY_DOWN");

        return solverFactory;
    }
}

@@ -839,16 +839,28 @@
 L_FILE =
+%0A           
  %22/org/j
@@ -958,16 +958,17 @@
 s.drl%22;%0A
+%0A
     priv
@@ -1013,16 +1013,28 @@
 CONFIG =
+%0A           
  %22/org/j
@@ -2818,32 +2818,109 @@
 meslotListSize, 
+%0A                                                                            
 dataset.roomList
@@ -3025,16 +3025,92 @@
 istSize,
+%0A                                                                           
  dataset

Remove unreadable long lines