package no.uis.ux.cipsi.net.monitoringbalancing.solver.move.factory;

import java.util.ArrayList;
import java.util.List;

import no.uis.ux.cipsi.net.monitoringbalancing.domain.MonitoringBalance;
import no.uis.ux.cipsi.net.monitoringbalancing.domain.MonitoringHost;
import no.uis.ux.cipsi.net.monitoringbalancing.domain.Node;
import no.uis.ux.cipsi.net.monitoringbalancing.domain.Switch;
import no.uis.ux.cipsi.net.monitoringbalancing.domain.TrafficFlow;
import no.uis.ux.cipsi.net.monitoringbalancing.domain.WeightedLink;
import no.uis.ux.cipsi.net.monitoringbalancing.solver.move.MonitoringChangeMove;

import org.optaplanner.core.impl.heuristic.move.Move;
import org.optaplanner.core.impl.heuristic.selector.move.factory.MoveListFactory;

import edu.uci.ics.jung.graph.Graph;

public class MonitoringChangeMoveFactory implements MoveListFactory<MonitoringBalance> {

    @Override
    public List<? extends Move> createMoveList(MonitoringBalance solution) {
        List<Move> moveList = new ArrayList<Move>();
        List<Switch> monitoringSwitches = solution.getMonitoringSwitches();
        List<MonitoringHost> monitoringHosts = solution.getMonitoringHosts();
        Graph<Node, WeightedLink> topology = solution.getTopology();
        for (Switch monitoringSwitch : monitoringSwitches) {
            for (MonitoringHost monitoringHost : monitoringHosts) {
                for (TrafficFlow trafficFlow : solution.getTrafficFlows()) {
                    if (trafficFlow.getOnPathMonitoringSwitches().contains(monitoringSwitch)){
                        // System.out.println("MonitoringChangeMoveFactory " + trafficFlow + " " + monitoringSwitch + " " + monitoringHost);
                        moveList.add(new MonitoringChangeMove(topology, trafficFlow, monitoringSwitch, monitoringHost));
                    }
                }
            }
        }

        return moveList;

        //        List<CloudComputer> cloudComputerList = cloudBalance.getComputerList();
        //        for (CloudProcess cloudProcess : cloudBalance.getProcessList()) {
        //            for (CloudComputer cloudComputer : cloudComputerList) {
        //                moveList.add(new CloudComputerChangeMove(cloudProcess, cloudComputer));
        //            }
        //        }
        //        return moveList;
    }

}

@@ -1242,22 +1242,30 @@
    for (
-Switch
+MonitoringHost
  monitor
@@ -1267,22 +1267,20 @@
 nitoring
-Switch
+Host
  : monit
@@ -1284,23 +1284,20 @@
 nitoring
-Switche
+Host
 s) %7B%0A   
@@ -1306,38 +1306,30 @@
        for (
-MonitoringHost
+Switch
  monitoringH
@@ -1319,36 +1319,38 @@
 witch monitoring
-Host
+Switch
  : monitoringHos
@@ -1338,36 +1338,39 @@
 tch : monitoring
-Host
+Switche
 s) %7B%0A           

Fix a host and use it for all flows.