Browse Source

Ga Algorithm for topologie

Tom Troppmann 4 years ago
parent
commit
99442f8346

+ 1 - 1
src/algorithm/example/BaseLine.java → src/algorithm/binary/BaseLine.java

@@ -1,4 +1,4 @@
-package algorithm.example;
+package algorithm.binary;
 
 import java.awt.BorderLayout;
 import java.awt.Component;

+ 1 - 2
src/algorithm/binary/GaAlgorithm.java

@@ -23,7 +23,7 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 	private boolean useFixedSpawProbability = false;
 	private double fixedMutateProbability = 0.02;
 	private boolean useFixedMutateProbability = false;
-	private boolean useIntervalMutation = true;
+	private boolean useIntervalMutation = false;
 	private double mutateProbabilityInterval = 0.01;
 	private double maxMutationPercent = 0.01;
 	private boolean moreInformation = false;
@@ -153,7 +153,6 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 			boolean boolValue = iter.next();
 			if(index == firstindex) {
 				iter.set(!boolValue);
-				//println("changed Value["+ index +"]");
 				if(mutationLocation.isEmpty()) break;
 				firstindex = mutationLocation.pollFirst();
 			}

+ 217 - 0
src/algorithm/topologie/GaAlgorithm.java

@@ -0,0 +1,217 @@
+package algorithm.topologie;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
+import algorithm.objectiveFunction.ObjectiveFunctionByCarlos;
+import api.TopologieAlgorithmFramework;
+import api.AlgorithmFrameworkFlex.Individual;
+import ui.model.DecoratedState;
+
+public class GaAlgorithm extends TopologieAlgorithmFramework {
+
+	private int popsize = 20;
+	private int maxGenerations = 100;
+	private double tournamentSize = 2.0;
+	private double fixedSwapProbability = 0.02;
+	private boolean useFixedSpawProbability = false;
+	private double fixedMutateProbability = 0.02;
+	private boolean useFixedMutateProbability = false;
+	private boolean useIntervalMutation = false;
+	private double mutateProbabilityInterval = 0.01;
+	private double maxMutationPercent = 0.01;
+	private boolean moreInformation = false;
+	
+	public GaAlgorithm(){
+		addIntParameter("popsize", popsize, intValue -> popsize = intValue, () -> popsize, 1);
+		addIntParameter("maxGenerations", maxGenerations, intValue -> maxGenerations = intValue, () -> maxGenerations, 1);
+		addDoubleParameter("tournamentSize", tournamentSize, doubleValue -> tournamentSize = doubleValue, () -> tournamentSize, 1.0);
+		addDoubleParameter("fixedSwapProbability", fixedSwapProbability, doubleValue -> fixedSwapProbability = doubleValue, () -> fixedSwapProbability, 0.0, 1.0);
+		addBooleanParameter("useFixedSpawProbability", useFixedSpawProbability, booleanValue -> useFixedSpawProbability = booleanValue);
+		addDoubleParameter("fixedMutateProbability", fixedMutateProbability, doubleValue -> fixedMutateProbability = doubleValue, () -> fixedMutateProbability, 0.0, 1.0);
+		addBooleanParameter("useFixedMutateProbability", useFixedMutateProbability, booleanValue -> useFixedMutateProbability = booleanValue);
+		addBooleanParameter("useIntervalMutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
+		addDoubleParameter("mutateProbabilityInterval", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
+		addDoubleParameter("maxMutationPercent", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);
+		addBooleanParameter("moreInformation", moreInformation, booleanValue -> moreInformation = booleanValue);
+
+	}
+	@Override
+	protected double evaluateState(DecoratedState actualstate) {
+		return ObjectiveFunctionByCarlos.getFitnessValueForState(actualstate);
+	}
+
+	@Override
+	protected Individual executeAlgo() {
+		resetWildcards();
+		Individual best = new Individual();
+		best.position = extractPositionAndAccess();
+		int problemSize =  best.position.size();
+		best.fitness = evaluatePosition(best.position);
+		List<Double> runList = new ArrayList<Double>();
+		runList.add(best.fitness);
+		console.println("Bit-Array_length: " + best.position.size());
+		List<Individual> population = initPopuluationRandom(problemSize, best);
+		for(int generation = 0; generation< maxGenerations; generation++) {
+			if(moreInformation)console.println("Generation" + generation + " start with Fitness: " + best.fitness);
+			for(Individual i : population) {
+				i.fitness = evaluatePosition(i.position);
+				if(moreInformation)console.println("Fitness" + i.fitness);
+				if(i.fitness < best.fitness) best = i;
+			}
+			runList.add(best.fitness);
+			List<Individual> childList = new ArrayList<Individual>();
+			for(int k = 0; k<popsize/2; k++) {
+				Individual parentA = selectAParent(population, popsize);
+				Individual parentB = selectAParent(population, popsize);
+				Individual childA = new Individual(parentA);
+				Individual childB = new Individual(parentB);
+				crossover(childA, childB, problemSize);
+				if(useIntervalMutation)mutateInterval(childA, problemSize);else mutate(childA, problemSize);
+				if(useIntervalMutation)mutateInterval(childB, problemSize);else mutate(childB, problemSize);
+				childList.add(childA);
+				childList.add(childB);
+			}
+			population = childList;
+			if(moreInformation)console.println("________________");
+			if(cancel)return null;
+		}
+		
+		console.println("   End with:" + best.fitness);
+		this.runList = runList;
+		return best;
+	}
+
+	@Override
+	protected int getProgressBarMaxCount() {
+		return 0;
+	}
+
+	@Override
+	protected String algoInformationToPrint() {
+		return "GA for topologie generation";
+	}
+
+	@Override
+	protected String plottFileName() {
+		return "ga-topologie.txt";
+	}
+	/**
+	 * Initialize the Population with Individuals that have a random Position.
+	 */
+	private List<Individual> initPopuluationRandom(int problemSize, Individual startIndidual){
+		List<Individual> population =  new ArrayList<Individual>();
+		for(int i = 0; i < popsize -1; i++) {
+			population.add(createRandomIndividualWithoutFitness(problemSize));
+		}
+		//Add Start Position
+		population.add(new Individual(startIndidual));
+		return population;
+	}
+	
+	private Individual createRandomIndividualWithoutFitness(int problemSize) {
+		//create Random Individual Without Fitness
+		Individual result = new Individual();
+		result.position = new ArrayList<Integer>();
+		for (int index = 0; index < problemSize; index++){
+			result.position.add(Random.nextIntegerInRange(0, this.getMaximumIndexObjects(index) + 1));
+		}
+		//console.println("[" +result.position.stream().map(Object::toString).collect(Collectors.joining(", ")) + "]");
+		return result;
+	}
+	
+	/**
+	 * Algorithm 32 Tournament Selection.
+	 * The fitnessValues are calculated for the Population List.
+	 * PseudoCode
+	 */
+	private Individual selectAParent(List<Individual> population,int popsize) {
+		Individual tournamentBest = population.get(Random.nextIntegerInRange(0, popsize));
+		double participants;
+		for(participants = tournamentSize ; participants >= 2; participants -= 1.0) {
+			Individual next = population.get(Random.nextIntegerInRange(0, popsize));
+			if(next.fitness < tournamentBest.fitness) tournamentBest = next;
+		}
+		//if tournament size is not a whole number like 2.5 or 3.6
+		//the remaining part is the chance to fight another time; 2.7 -> 70% chance to fight a second time
+		if( participants > 1) {		
+			if(Random.nextDouble() < participants - 1.0) {
+				//println("Chance to find a match");
+				Individual next = population.get(Random.nextIntegerInRange(0, popsize));
+				if(next.fitness < tournamentBest.fitness) tournamentBest = next;
+			}
+		}
+		return tournamentBest;
+	}
+	/** 
+	 * Algorithm 25 Uniform Crossover.
+	 * Probability is set to 1/Problemsize when not changed.
+	 */
+	private void crossover(Individual childA, Individual childB, int problemSize) {
+		double probability = (this.useFixedSpawProbability) ? this.fixedSwapProbability : 1.0/(double)problemSize;
+		ListIterator<Integer> iterA = childA.position.listIterator();
+		ListIterator<Integer> iterB = childB.position.listIterator();
+		for(int i= 0; i < problemSize; i++) {
+			int intA = iterA.next();
+			int intB = iterB.next();
+			if(Random.nextDouble() <=  probability ) {
+				//Swap 
+				iterA.set(intB);
+				iterB.set(intA);
+			}
+		}
+	}
+	/**
+	 * Algorithm 22 Bit-Flip Mutation.
+	 * 
+	 */
+	private void mutate(Individual child, int problemSize) {
+		double probability = (this.useFixedMutateProbability) ? this.fixedMutateProbability : 1.0/(double)problemSize;
+		ListIterator<Integer> iter = child.position.listIterator();
+		while(iter.hasNext()) {
+			int index = iter.nextIndex();
+			Integer intValue = iter.next();
+			if(Random.nextDouble() <=  probability) {
+				iter.set(Random.nextIntegerInRangeExcept(0, this.getMaximumIndexObjects(index), intValue));
+			}
+		}
+	}
+	/**
+	 * Algorithm rolf
+	 * 
+	 */
+	private void mutateInterval(Individual child, int problemSize) {
+		//If not mutate skip
+		if(Random.nextDouble() >  this.mutateProbabilityInterval) {
+			return;
+		}
+		//println("problemSize:" + problemSize + "    maxMutationPercent:" + maxMutationPercent);
+		int maximumAmountOfMutatedBits = Math.max(1, (int)Math.round(((double) problemSize) * this.maxMutationPercent));
+		int randomUniformAmountOfMutatedValues = Random.nextIntegerInRange(1,maximumAmountOfMutatedBits + 1);
+		
+		//println("max:" + maximumAmountOfMutatedBits + "   actual:" + randomUniformAmountOfMutatedValues);
+		TreeSet<Integer> mutationLocation = new TreeSet<Integer>(); //sortedSet
+		//Choose the location to mutate
+		for(int i = 0; i< randomUniformAmountOfMutatedValues; i++) {
+			boolean success = mutationLocation.add(Random.nextIntegerInRange(0, problemSize));
+			if(!success) i--; //can be add up to some series long loops if maximumAmountOfMutatedBits get closed to problemsize.
+		}
+		//println("Set:" + mutationLocation);
+		ListIterator<Integer> iter = child.position.listIterator();
+		if(mutationLocation.isEmpty()) return;
+		int firstindex = mutationLocation.pollFirst();
+		while(iter.hasNext()) {
+			int index = iter.nextIndex();
+			int intValue = iter.next();
+			if(index == firstindex) {
+				iter.set(Random.nextIntegerInRangeExcept(0, this.getMaximumIndexObjects(index), intValue));
+				//println("changed Value["+ index +"]");
+				if(mutationLocation.isEmpty()) break;
+				firstindex = mutationLocation.pollFirst();
+			}
+		}
+	}
+}

+ 3 - 0
src/api/AlgorithmFrameworkFlex.java

@@ -731,6 +731,9 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		return initialState;
 	}
 	
+	
+	
+
 	/**
 	 * Method to extract the Informations recursively out of the Model.
 	 * @param nodes

+ 247 - 27
src/api/TopologieAlgorithmFramework.java

@@ -14,9 +14,12 @@ import java.math.RoundingMode;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.function.BiFunction;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -37,8 +40,9 @@ import javax.swing.JProgressBar;
 import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
 import javax.swing.text.NumberFormatter;
-
 import classes.AbstractCpsObject;
+import classes.Category;
+import classes.CpsEdge;
 import classes.CpsUpperNode;
 import classes.Flexibility;
 import classes.HolonElement;
@@ -50,7 +54,9 @@ import ui.controller.FlexManager.FlexState;
 import ui.controller.FlexManager.FlexWrapper;
 import ui.model.DecoratedGroupNode;
 import ui.model.DecoratedState;
+import ui.model.IntermediateCableWithState;
 import ui.model.Model;
+import ui.model.DecoratedCable.CableState;
 import ui.model.DecoratedHolonObject.HolonObjectState;
 import ui.model.DecoratedSwitch.SwitchState;
 import ui.model.DecoratedNetwork;
@@ -59,7 +65,7 @@ import ui.view.Console;
 public abstract class TopologieAlgorithmFramework implements AddOn{
 	//Algo
 	protected int rounds = 1;
-	
+	protected int amountOfNewCables = 3;
 	
 	
 	//Panel
@@ -73,8 +79,26 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	
 	
 	//access
-	private ArrayList<AccessWrapper> access;
+	private ArrayList<AccessWrapper> accessWildcards = new  ArrayList<AccessWrapper>();
 	LinkedList<List<Integer>> resetChain = new LinkedList<List<Integer>>();
+	
+	
+	private HashMap<Integer, AbstractCpsObject> accessIntToObject = new HashMap<Integer, AbstractCpsObject>();
+	private HashMap<AbstractCpsObject, Integer> accessObjectToInt = new HashMap<AbstractCpsObject, Integer>();
+	private HashMap<Integer, AbstractCpsObject> accessIntegerToWildcard = new HashMap<Integer, AbstractCpsObject>();
+	
+	
+	
+	
+	
+	
+	
+	private HashSet<IndexCable> cableSet = new HashSet<IndexCable>();
+	private HashMap<IndexCable, CpsEdge> addedCableMap = new HashMap<IndexCable, CpsEdge>();
+	private int countForAccessMap = 0;
+	
+	
+	
 	boolean algoUseElements = false, algoUseSwitches = true, algoUseFlexes = true;
 	
 	//time
@@ -133,6 +157,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		parameterPanel.setPreferredSize(new Dimension(510,300));
 		borderPanel.setLayout(new BoxLayout(borderPanel, BoxLayout.PAGE_AXIS));
 		addIntParameter("Rounds", rounds, intInput -> rounds = intInput, () -> rounds, 1);
+		addIntParameter("amountOfNewCables", amountOfNewCables, intInput -> amountOfNewCables = intInput, () -> amountOfNewCables, 0);
 		JScrollPane scrollPane = new JScrollPane(borderPanel);
 		scrollPane.setBounds(10, 0, 850, 292);
 		scrollPane.setBorder(BorderFactory.createEmptyBorder());
@@ -143,6 +168,11 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		progressBar.setBounds(900, 35, 185, 20);
 		progressBar.setStringPainted(true);
 		parameterPanel.add(progressBar);
+		
+		JButton addCategoryButton = new JButton("Add Category");
+		addCategoryButton.setBounds(900, 65, 185, 30);
+		addCategoryButton.addActionListener(clicked -> createWildcardsCategory());
+		parameterPanel.add(addCategoryButton);
 		return parameterPanel;
 	}
 	private JPanel createButtonPanel() {
@@ -397,15 +427,25 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			console.println("Nothing to cancel.");
 		}
 	}
-	
+	private void createWildcardsCategory() {
+		Category category = control.searchCategory("Wildcards");
+		if(category == null) {
+			try {
+				control.addCategory("Wildcards");
+			} catch (IOException e) {
+				console.println("IO Exception - Creating WIldcards Category failed.");
+				System.out.println("IO Exception - Creating WIldcards Category failed.");
+				e.printStackTrace();
+			}
+		}
+	}
 	
 	private void fitness() {
 		if(runThread.isAlive()) {
 			console.println("Run have to be cancelled First.");
 			return;
 		}
-		double currentFitness = evaluatePosition(extractPositionAndAccess());
-		resetChain.removeLast();
+		double currentFitness = evaluateNetwork();
 		console.println("Actual Fitnessvalue: " + currentFitness);
 	}
 	
@@ -419,12 +459,16 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 //		startTime = endTime;
 		setState(positionToEvaluate); // execution time critical
 
+		return evaluateNetwork();
+	}
+
+	private double evaluateNetwork() {
 		control.calculateStateOnlyForCurrentTimeStep();
 		DecoratedState actualstate = control.getSimManager().getActualDecorState();
-		double result = evaluateState(actualstate);
-		return result;
+		return evaluateState(actualstate);
 	}
-
+	
+	
 	protected abstract double evaluateState(DecoratedState actualstate);
 
 	
@@ -497,7 +541,6 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 
 	private void executeAlgoWithParameter(){
 		double startFitness = evaluatePosition(extractPositionAndAccess());
-		console.println("BitLength: " + access.size());
 		resetChain.removeLast();
 		runPrinter.openStream();
 		runPrinter.println("");
@@ -519,12 +562,11 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			runPrinter.println(stringStatFromActualState());
 			runPrinter.println("Result: " + roundBest.fitness + " ExecutionTime:" + executionTime);
 			runPrinter.closeStream();
-			resetState();
+			//resetState();
 			if(roundBest.fitness < runBest.fitness) runBest = roundBest;
 		}
 		
 		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
-		this.extractPositionAndAccess();
 		setState(runBest.position);
 		updateVisual();
 		console.println("Start: " + startFitness);
@@ -585,11 +627,14 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	 * @param position
 	 */
 	private void setState(List<Integer> position) {
-		int i = 0;
-		for(Integer integer: position) {
-			access.get(i++).setState(integer);
+		this.removeAllAddedCables();
+		for(int i = 0; i < this.amountOfNewCables; i++) {
+			generateCable(position.get(2 * i), position.get(2 * i + 1));
+		}
+		int count = 0;
+		for(int i = 2 * this.amountOfNewCables; i < position.size(); i++) {
+			accessWildcards.get(count++).setState(position.get(i));
 		}
-		
 }
 
 
@@ -601,29 +646,128 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	 */
 	protected List<Integer> extractPositionAndAccess() {
 		Model model = control.getModel();
-		access= new ArrayList<AccessWrapper>();
+		
+		
+		
+		
+		
+		//-->reset
+		accessWildcards.clear();
+		this.countForAccessMap = 0;
+		accessIntToObject.clear();
+		accessObjectToInt.clear();
+		cableSet.clear();
+		//<---
+		Category category = control.searchCategory("Wildcards");
+		if(category != null) {
+			for(int count = 0; count < category.getObjects().size(); count++ ) {
+				accessIntegerToWildcard.put(count + 1, category.getObjects().get(count));
+			}			
+		}else {
+			console.println("No 'Wildcards' Category");
+		}
+		
+		
+		
 		List<Integer> initialState = new ArrayList<Integer>();
-		rollOutNodes((dGroupNode != null)? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurIteration());			
+		generateAccess(model.getObjectsOnCanvas());			
+		addCables(model.getEdgesOnCanvas());
+		getCables(model.getObjectsOnCanvas());
+		for(int i = 0; i < this.amountOfNewCables; i++) {
+			initialState.add(0);
+			initialState.add(0);
+		}
+		for(int i = 0; i < accessWildcards.size(); i++) {
+			initialState.add(0);
+		}
 		resetChain.add(initialState);
-		//console.println(access.stream().map(Object::toString).collect(Collectors.joining(", ")));
+		//console.println(accessIntToObject.values().stream().map(hO -> hO.getName()).collect(Collectors.joining(", ")));
+		//console.println(cableSet.stream().map(Object::toString).collect(Collectors.f(", ")));
 		return initialState;
 	}
 	
+	
+	
+	
 	/**
 	 * Method to extract the Informations recursively out of the Model.
 	 * @param nodes
 	 * @param positionToInit
 	 * @param timeStep
 	 */
-	private void rollOutNodes(List<AbstractCpsObject> nodes, List<Integer> positionToInit, int timeStep) {
+	private void generateAccess(List<AbstractCpsObject> nodes) {
+		for(AbstractCpsObject aCps : nodes) {
+			if(aCps instanceof HolonObject) {
+				HolonObject hO = (HolonObject) aCps;
+				accessIntToObject.put(++countForAccessMap, hO);
+				accessObjectToInt.put(hO, countForAccessMap);
+				if(hO.getName().equals("Wildcard")) {
+					accessWildcards.add(new AccessWrapper(hO));
+				}
+			}
+			else if(aCps instanceof CpsUpperNode) {
+				generateAccess(((CpsUpperNode)aCps).getNodes());
+			}
+		}
+	}
+	private void getCables(List<AbstractCpsObject> nodes) {
 		for(AbstractCpsObject aCps : nodes) {
 			if(aCps instanceof CpsUpperNode) {
-				rollOutNodes(((CpsUpperNode)aCps).getNodes(), positionToInit ,timeStep );
+				CpsUpperNode aUpperNode = (CpsUpperNode)aCps;
+				addCables(aUpperNode.getNodeEdges());
+				addCables(aUpperNode.getOldEdges());
+				getCables(((CpsUpperNode)aCps).getNodes());
 			}
 		}
 	}
 	
 	
+	protected void resetWildcards() {
+		this.accessWildcards.forEach(wrapper -> wrapper.resetState());
+	}
+	/**
+	 * All Nodes have to be in the access map !!
+	 * @param cables
+	 */
+	private void addCables(List<CpsEdge> edges) {
+		for (CpsEdge edge : edges) {
+			edge.setUnlimitedCapacity(true);
+			//console.println("Cable from " + edge.getA().getName() + " to " + edge.getB().getName());
+			if(!accessObjectToInt.containsKey(edge.getA())) {
+				console.println("Node A from Edge[" + edge + "] not exist");
+				continue;
+			} else if (!accessObjectToInt.containsKey(edge.getB())) {
+				console.println("Node B from Edge[" + edge + "] not exist");
+				continue;
+			}
+			cableSet.add(new IndexCable(accessObjectToInt.get(edge.getA()), accessObjectToInt.get(edge.getB())));
+		}
+	}
+	
+	
+	
+	private void generateCable(int index1, int index2) {
+		//If cable isnt valid
+		if(index1 == 0 || index2 == 0 || index1 == index2) {
+			//console.println("Cable("+index1+","+index2+ ") isn't valid");
+			return;
+		}
+		IndexCable cable = new IndexCable(index1, index2);
+		//if cable is in existing cables
+		if(cableSet.contains(cable) || addedCableMap.containsKey(cable)) {
+			//console.println("Cable("+index1+","+index2+ ") already exist");
+			return;
+		}
+		
+		CpsEdge edge = new CpsEdge(accessIntToObject.get(index1), accessIntToObject.get(index2));
+		edge.setUnlimitedCapacity(true);
+		control.getModel().getEdgesOnCanvas().add(edge);
+		addedCableMap.put(cable, edge);
+	}
+	private void removeAllAddedCables() {
+		control.getModel().getEdgesOnCanvas().removeAll(addedCableMap.values());
+		addedCableMap.clear();
+	}
 	
 	
 	private String stringStatFromActualState() {
@@ -726,6 +870,9 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		this.control = control;
 	}
 	
+	public int getMaximumIndexObjects(int index) {
+		return (index < 2 * amountOfNewCables)? this.countForAccessMap: accessWildcards.size();
+	}
 	
 	
 	private class RunProgressBar{
@@ -805,18 +952,33 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	 * A Wrapper Class for Access HolonElement and HolonSwitch in one Element and not have to split the List.
 	 */
 	private class AccessWrapper {
-		
-		public AccessWrapper(int a) {
-			
+		int state = 0;
+		HolonObject wildcard;
+		public AccessWrapper(HolonObject wildcard) {
+			this.wildcard = wildcard;
 		}
 		
 		public void setState(int state) {
-			//TODO set state
+			if(this.state !=  state) {
+				this.state = state;
+				wildcard.getElements().clear();
+				if(state > 0) {
+					HolonObject hO = (HolonObject)accessIntegerToWildcard.get(state);
+					if(hO == null) {
+						console.println("null set state(" + state + ")");
+					}else {
+						wildcard.getElements().addAll(hO.getElements());											
+					}
+				}
+			}
+		}
+		public void resetState() {
+			state = 0;
+			wildcard.getElements().clear();
 		}
-		
 		
 		public String toString() {
-			return "Hollow";
+			return wildcard + "have state: " + state;
 		}
 	}
 	
@@ -859,6 +1021,26 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			}
 			return result;
 		}
+		/**
+		 * Random Int in Range [min;max[ with UniformDistirbution
+		 * @param min
+		 * @param max
+		 * @param valueBetween a value between min and max
+		 * @return
+		 */
+		public static int nextIntegerInRangeExcept(int min, int max,int valueBetween) {
+			int result = min;
+			try {
+				result = min + random.nextInt((max - 1) - min);
+				if(result >= valueBetween) {
+					result++;
+				}
+			}catch(java.lang.IllegalArgumentException e){
+				System.err.println("min : " + min + " max : " + max);
+				System.err.println("max should be more then min");
+			}
+			return result;
+		}
 	}
 	
 	private   class  Handle<T>{
@@ -926,4 +1108,42 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	}
 	
 	
+	
+	
+	
+	public class IndexCable{
+	    public final Integer first;
+	    public final Integer second;
+
+	    public IndexCable(Integer first, Integer second) {
+	    	if(first.compareTo(second) == 0) {
+	    		throw new IllegalArgumentException("(" + first + "==" + second + ")" 
+	    							+ "Two ends of the cable are at the same Object");
+	    	} else if(first.compareTo(second) < 0) {
+	    		this.first = first;
+	    		this.second = second;	    		
+	    	}else {
+	    		this.first = second;
+	    		this.second = first;
+	    	}
+	    }
+
+	    @Override
+	    public boolean equals(Object o) {
+	        if (!(o instanceof IndexCable)) {
+	            return false;
+	        }
+	        IndexCable p = (IndexCable) o;
+	        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
+	    }
+
+	    @Override
+	    public int hashCode() {
+	        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
+	    }
+	    @Override
+	    public String toString() {
+			return "{" + first + "," + second + "}";
+	    }
+	}
 }

+ 1 - 1
src/ui/view/AddOnWindow.java

@@ -91,7 +91,7 @@ public class AddOnWindow extends JFrame{
 	 */
 	private void openJavaFile() {
 		JFileChooser fileChooser = new JFileChooser();
-		fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")+"/src/exampleAlgorithms/"));
+		fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")+"/src/algorithm/"));
 		fileChooser.setFileFilter(new FileNameExtensionFilter("JAVA Source Files", "java"));
 		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
 		fileChooser.setAcceptAllFileFilterUsed(false);

+ 1 - 0
src/ui/view/DisplayedInformationPopUp.java

@@ -50,6 +50,7 @@ public class DisplayedInformationPopUp extends JDialog {
 
 		connectionCheckbox = new JCheckBox("Display Connection Properties");
 		connectionCheckbox.setBounds(19, 57, 300, 23);
+		connectionCheckbox.setSelected(true);
 		contentPanel.add(connectionCheckbox);
 
 		objectEnergyCheckbox.setSelected(canvas.getShowedInformation()[1]);