123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package holeg.ui.model;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Logger;
- import java.util.stream.Collectors;
- import holeg.model.Edge;
- import holeg.model.Flexibility;
- import holeg.model.GroupNode;
- import holeg.model.HolonElement;
- /**
- * The Class Model is the class where everything is saved. All changes made to
- * the Data is managed via a controller.
- *
- * @author Gruppe14
- */
- public class Model {
- private static final Logger log = Logger.getLogger(Model.class.getName());
- private int currentIteration = 0;
- private int maxIterations=100;
-
- /** the amount of iterations */
-
- /**
- * All implemented FairnessModels:<br>
- * {@link FairnessModel#MininumDemandFirst}<br>
- * {@link FairnessModel#AllEqual}
- */
- public enum FairnessModel{
- /**
- * One Element of each HolonObject will be powered first, starting with the
- * smallest Demand. If ale HolonObjects have an active Element, the
- * simulation will try to fully supply as many HolonObjects as possible.
- */
- MininumDemandFirst,
- /**
- * All HolonObjects will receive the same amount of energy.
- */
- AllEqual
- }
- /** the Fairness model in use */
- private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;
-
- private GroupNode canvas = new GroupNode("Canvas");
- /*
- * Array of all CpsObjects in our canvas. It is set by default as an empty
- * list.
- */
- private List<Edge> edgesOnCanvas = new ArrayList<>();
-
- public Model() {
- log.fine("Init Model");
- }
-
- public GroupNode getCanvas() {
- return canvas;
- }
-
- /**
- * Get all Edges on the Canvas.
- *
- * @return the edgesOnCanvas
- */
- public List<Edge> getEdgesOnCanvas() {
- return edgesOnCanvas;
- }
- /**
- * Sets the edges on the Canvas.
- *
- * @param arrayList the edgesOnCanvas to set
- */
- public void setEdgesOnCanvas(ArrayList<Edge> arrayList) {
- this.edgesOnCanvas = arrayList;
- }
- /**
- * Adds an Edge to The Canvas.
- *
- * @param edge the edgesOnCanvas to add
- */
- public void addEdgeOnCanvas(Edge edge) {
- this.edgesOnCanvas.add(edge);
- }
- /**
- * Remove an edge from the Canvas.
- *
- * @param edge the edge to remove
- */
- public void removeEdgesOnCanvas(Edge edge) {
- this.edgesOnCanvas.remove(edge);
- }
- /**
- * Returns the maximum iterations.
- *
- * @return iterations
- */
- public int getMaxIterations() {
- return maxIterations;
- }
- /**
- * Returns the current iteration.
- *
- * @return current iteration
- */
- public int getCurrentIteration() {
- return currentIteration;
- }
- /**
- * sets the current Iteration.
- *
- * @param curIT the current Iteration
- */
- public void setCurrentIteration(int value) {
- this.currentIteration = value;
- }
- public List<HolonElement> getAllHolonElements() {
- return canvas.getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements()).collect(Collectors.toList());
- }
-
- public List<Flexibility> getAllFlexibilities() {
- return canvas.getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements().flatMap(ele -> ele.flexList.stream())).collect(Collectors.toList());
- }
-
- public void reset() {
- resetFlexibilities();
- resetEdges();
- }
-
- private void resetFlexibilities() {
- getAllFlexibilities().forEach(flex -> flex.reset());
- }
- private void resetEdges() {
- this.getEdgesOnCanvas().forEach(edge -> edge.reset());
- }
-
-
- /**
- * @param iterations the number of steps for this simulation
- */
- public void setIterations(int iterations){
- this.maxIterations=iterations;
- }
-
- /**
- * @return the fairnessModel
- */
- public FairnessModel getFairnessModel() {
- return fairnessModel;
- }
-
- /**
- * @param fairnessModel the fairnessModel to set
- */
- public void setFairnessModel(FairnessModel fairnessModel) {
- this.fairnessModel = fairnessModel;
- }
-
- public void clear() {
- this.edgesOnCanvas.clear();
- canvas.clear();
- }
- }
|