diff --git a/src/main/java/projects/LA_Alpha/CustomGlobal.java b/src/main/java/projects/LA_Alpha/CustomGlobal.java new file mode 100644 index 0000000000000000000000000000000000000000..0387cc54d5363441c96077721ebffa85d06658bf --- /dev/null +++ b/src/main/java/projects/LA_Alpha/CustomGlobal.java @@ -0,0 +1,111 @@ +/* +BSD 3-Clause License + +Copyright (c) 2007-2013, Distributed Computing Group (DCG) + ETH Zurich + Switzerland + dcg.ethz.ch + 2017-2018, André Brait + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package projects.LA_Alpha; + +import sinalgo.nodes.Node; +import sinalgo.runtime.AbstractCustomGlobal; +import sinalgo.tools.Tools; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.*; + +/** + * This class holds customized global state and methods for the framework. The + * only mandatory method to overwrite is <code>hasTerminated</code> <br> + * Optional methods to override are + * <ul> + * <li><code>customPaint</code></li> + * <li><code>handleEmptyEventQueue</code></li> + * <li><code>onExit</code></li> + * <li><code>preRun</code></li> + * <li><code>preRound</code></li> + * <li><code>postRound</code></li> + * <li><code>checkProjectRequirements</code></li> + * </ul> + * + * @see sinalgo.runtime.AbstractCustomGlobal for more details. <br> + * In addition, this class also provides the possibility to extend the + * framework with custom methods that can be called either through the menu + * or via a button that is added to the GUI. + */ +public class CustomGlobal extends AbstractCustomGlobal { + + @Override + public boolean hasTerminated() { + return false; + } + + /** + * An example of a method that will be available through the menu of the GUI. + */ + @AbstractCustomGlobal.GlobalMethod(menuText = "Echo") + public void echo() { + // Query the user for an input + String answer = JOptionPane.showInputDialog(null, "This is an example.\nType in any text to echo."); + // Show an information message + JOptionPane.showMessageDialog(null, "You typed '" + answer + "'", "Example Echo", + JOptionPane.INFORMATION_MESSAGE); + } + + /** + * An example to add a button to the user interface. In this sample, the button + * is labeled with a text 'GO'. Alternatively, you can specify an icon that is + * shown on the button. See AbstractCustomGlobal.CustomButton for more details. + */ + @AbstractCustomGlobal.CustomButton(buttonText = "GO", toolTipText = "A sample button") + public void sampleButton() { + JOptionPane.showMessageDialog(null, "You Pressed the 'GO' button."); + } + + /** + * Function for linking all the nodes together + */ + @AbstractCustomGlobal.GlobalMethod(menuText = "Link Everything") + public void linkEverything() { + List<Node> nodeList = new ArrayList<>(); + Tools.getNodeList().iterator().forEachRemaining(nodeList::add); + for (int i = 0; i < nodeList.size(); i++) { + for (int j = 0; j < nodeList.size(); j++) { + nodeList.get(i).addConnectionTo(nodeList.get((j))); + } + } + Tools.repaintGUI(); + } + +} diff --git a/src/main/java/projects/LA_Alpha/LogL.java b/src/main/java/projects/LA_Alpha/LogL.java new file mode 100644 index 0000000000000000000000000000000000000000..658b2e984bdea6e88255963bc857d0d41c3209a8 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/LogL.java @@ -0,0 +1,44 @@ +/* +BSD 3-Clause License + +Copyright (c) 2007-2013, Distributed Computing Group (DCG) + ETH Zurich + Switzerland + dcg.ethz.ch + 2017-2018, André Brait + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package projects.LA_Alpha; + +/** + * Enumerates the log-levels. Levels above THRESHOLD will be included in the + * log-file. The levels below (with a higher enumeration value) not. + */ +public class LogL extends sinalgo.tools.logging.LogL { +} diff --git a/src/main/java/projects/LA_Alpha/models/connectivityModels/readme.txt b/src/main/java/projects/LA_Alpha/models/connectivityModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..693acbf0dcebaf9382c48dc7e2dd33db81f1e115 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/models/connectivityModels/readme.txt @@ -0,0 +1 @@ +Place all your custom connectivity models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/models/distributionModels/readme.txt b/src/main/java/projects/LA_Alpha/models/distributionModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..8aaa93d177444314a040160027c7a5fb1a1ec951 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/models/distributionModels/readme.txt @@ -0,0 +1 @@ +Place all your custom distribution models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/models/interferenceModels/readme.txt b/src/main/java/projects/LA_Alpha/models/interferenceModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..45b4a9aa80563296e90c13c667a740f4978c7614 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/models/interferenceModels/readme.txt @@ -0,0 +1 @@ +Place all your custom interference models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/models/messageTransmissionModels/readme.txt b/src/main/java/projects/LA_Alpha/models/messageTransmissionModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2dcde95a9f41a1b250f60a747329cbe85c6a87a --- /dev/null +++ b/src/main/java/projects/LA_Alpha/models/messageTransmissionModels/readme.txt @@ -0,0 +1 @@ +Place all your custom message transmission models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/models/mobilityModels/readme.txt b/src/main/java/projects/LA_Alpha/models/mobilityModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..d94bc8185176f050dfb80cac1938a41da6de560e --- /dev/null +++ b/src/main/java/projects/LA_Alpha/models/mobilityModels/readme.txt @@ -0,0 +1 @@ +Place all your custom mobility models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/models/reliabilityModels/readme.txt b/src/main/java/projects/LA_Alpha/models/reliabilityModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..0136e13d5229bb2b53470444ed3aef8259b00136 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/models/reliabilityModels/readme.txt @@ -0,0 +1 @@ +Place all your custom reliability models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/nodes/edges/readme.txt b/src/main/java/projects/LA_Alpha/nodes/edges/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..97b95b0af0c06366834c779cc32961dfb2a964ad --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/edges/readme.txt @@ -0,0 +1 @@ +Place all your custom edge implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/nodes/messages/ClassificationResult.java b/src/main/java/projects/LA_Alpha/nodes/messages/ClassificationResult.java new file mode 100644 index 0000000000000000000000000000000000000000..96463337e2d0af63c5adfb9031fe2379bf190aaf --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/messages/ClassificationResult.java @@ -0,0 +1,27 @@ +package projects.LA_Alpha.nodes.messages; + +import java.util.Set; + +import lombok.Getter; +import lombok.Setter; + +public class ClassificationResult { + @Getter + @Setter + Set<Integer> nextRoundValue; + + @Getter + @Setter + NodeClass clazz; + + @Setter + @Getter + boolean decided; + + public ClassificationResult(Set<Integer> nextRoundValue, NodeClass clazz, boolean decided) { + this.nextRoundValue = nextRoundValue; + this.clazz = clazz; + this.decided = decided; + } + +} diff --git a/src/main/java/projects/LA_Alpha/nodes/messages/ClassifierMessage.java b/src/main/java/projects/LA_Alpha/nodes/messages/ClassifierMessage.java new file mode 100644 index 0000000000000000000000000000000000000000..18241f7198efd79a07586354e027d1b5d9bacf45 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/messages/ClassifierMessage.java @@ -0,0 +1,23 @@ +package projects.LA_Alpha.nodes.messages; + +import java.util.HashSet; +import java.util.Set; + +import sinalgo.nodes.messages.Message; + +public class ClassifierMessage extends Message { + + Integer k; + Set<Integer> v; + + public ClassifierMessage(Integer k, Set<Integer> v) { + this.k = k; + this.v = v; + } + + @Override + public Message clone() { + return new ClassifierMessage(k, new HashSet<>(v)); + } + +} diff --git a/src/main/java/projects/LA_Alpha/nodes/messages/NodeClass.java b/src/main/java/projects/LA_Alpha/nodes/messages/NodeClass.java new file mode 100644 index 0000000000000000000000000000000000000000..18099c8cdc0e52599e6775abe7a0a5a0a67f759d --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/messages/NodeClass.java @@ -0,0 +1,5 @@ +package projects.LA_Alpha.nodes.messages; + +public enum NodeClass { + MASTER, SLAVE, UNDEFINED +} diff --git a/src/main/java/projects/LA_Alpha/nodes/messages/readme.txt b/src/main/java/projects/LA_Alpha/nodes/messages/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..8baf37ab9d733601690609ba33829be49aaf3cbb --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/messages/readme.txt @@ -0,0 +1 @@ +Place all your custom message implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/ClassifierResponseMessages.java b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/ClassifierResponseMessages.java new file mode 100644 index 0000000000000000000000000000000000000000..a72a6743aec1c811e410d4bb5d5b595780e1f66e --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/ClassifierResponseMessages.java @@ -0,0 +1,29 @@ +package projects.LA_Alpha.nodes.nodeImplementations; + +import java.util.HashSet; +import java.util.Set; + +import lombok.Getter; +import lombok.Setter; +import sinalgo.nodes.messages.Message; + +public class ClassifierResponseMessages extends Message { + + @Getter + @Setter + Set<Integer> vi; + + @Getter + @Setter + Integer li; + + public ClassifierResponseMessages(Set<Integer> vi, Integer li) { + this.vi = vi; + this.li = li; + } + + @Override + public Message clone() { + return new ClassifierResponseMessages(new HashSet<>(vi), li); + } +} diff --git a/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/ClassifierSteps.java b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/ClassifierSteps.java new file mode 100644 index 0000000000000000000000000000000000000000..2c3838732973484f377db816df4de2ab5625f697 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/ClassifierSteps.java @@ -0,0 +1,5 @@ +package projects.LA_Alpha.nodes.nodeImplementations; + +public enum ClassifierSteps { + SEND_MESSAGE, RECEIVE_MESSAGE +} diff --git a/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/LA_AlphaNode.java b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/LA_AlphaNode.java new file mode 100644 index 0000000000000000000000000000000000000000..086e5bca09199d56d90d1a247ad205fa05c09260 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/LA_AlphaNode.java @@ -0,0 +1,214 @@ +package projects.LA_Alpha.nodes.nodeImplementations; + +import projects.LA_Alpha.CustomGlobal; +import projects.LA_Alpha.nodes.messages.ClassificationResult; +import projects.LA_Alpha.nodes.messages.ClassifierMessage; +import projects.LA_Alpha.nodes.messages.NodeClass; +import sinalgo.exception.WrongConfigurationException; +import sinalgo.gui.transformation.PositionTransformation; +import sinalgo.nodes.Node; +import sinalgo.nodes.messages.Inbox; +import sinalgo.nodes.messages.Message; +import sinalgo.tools.Tools; +import java.util.Map; +import java.util.Set; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.awt.Color; +import java.awt.Graphics; +import java.util.ArrayList; +import java.util.Arrays; + +public class LA_AlphaNode extends Node { + static final int H = 20; + + static Map<Long, NodeData> nodesDataMap = new HashMap<>(); + + Nodestatus nodeState = Nodestatus.READY; + + @Override + public void handleMessages(Inbox inbox) { + List<ClassifierResponseMessages> classifierResponseMessages = new ArrayList<>(); + + // if it is defect it doesn't receive any messages + if (this.isDefect()) { + while (inbox.hasNext()) { + inbox.next(); + } + return; + } + + while (inbox.hasNext()) { + Message message = inbox.next(); + if (message instanceof ClassifierResponseMessages) { + classifierResponseMessages.add((ClassifierResponseMessages) message); + } else if (message instanceof ClassifierMessage) { + this.send(new ClassifierResponseMessages(this.getNodeData().vi, this.getNodeData().li), + inbox.getSender()); + } + } + + if (!classifierResponseMessages.isEmpty()) { + this.classifier(ClassifierSteps.RECEIVE_MESSAGE, classifierResponseMessages); + } + + } + + private boolean isDefect() { + boolean defective = (Tools.getGlobalTime() % (this.getID() + 1)) == 0; + + if (defective) { + this.setColor(Color.GRAY); + } else { + this.setColor(Color.black); + } + + return defective; + } + + @Override + public void preStep() { + if (!this.getNodeData().decided && !this.isDefect()) { + ClassificationResult res = this.classifier(ClassifierSteps.SEND_MESSAGE, null); + if (res == null) { + return; + } + if (res.isDecided()) { + this.getNodeData().decided = res.isDecided(); + this.getNodeData().vi = res.getNextRoundValue(); + } else if (res.getClazz() == NodeClass.MASTER) { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li + (int) (H / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + } else { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li - (int) (H / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + } + } + } + + @Override + public void init() { + Integer li = H / 2; + // Integer setSize = (int) (Math.random() * (H + 1)); + boolean decided = false; + Set<Integer> vi = new HashSet<Integer>(); + vi.add(((int) this.getID())); + // for (int i = 0; i < setSize; i++) { + // Integer randomValue = (int) (Math.random() * (H + 1)); + // vi.add(randomValue); + // } + NodeData nodeData = new NodeData(vi, li, decided); + nodesDataMap.put(this.getID(), nodeData); + } + + @Override + public void neighborhoodChange() { + } + + @Override + public void postStep() { + } + + @Override + public void checkRequirements() throws WrongConfigurationException { + } + + private ClassificationResult classifier(ClassifierSteps step, List<ClassifierResponseMessages> receivedMessages) { + if (step == ClassifierSteps.SEND_MESSAGE) { + this.sendClassifierMessage(); + return null; + } + + if (step == ClassifierSteps.RECEIVE_MESSAGE) { + List<Set<Integer>> U = new ArrayList<>(); + + for (int i = 0; i < receivedMessages.size(); i++) { + ClassifierResponseMessages currentMessage = receivedMessages.get(i); + U.add(currentMessage.vi); + } + + if (U.size() == 0 || this.inclusionTest(U)) { + this.getNodeData().decided = true; + return new ClassificationResult(nodesDataMap.get(this.getID()).vi, NodeClass.UNDEFINED, true); + } + + Set<Integer> w = new HashSet<>(); + + for (Set<Integer> x : U) { + w.addAll(x); + } + + Integer h_w = w.size(); + Integer k = nodesDataMap.get(this.getID()).li; + + if (h_w > k) { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li + (int) (H / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + this.setColor(Color.green); + this.getNodeData().vi = new HashSet<>(w); + + return new ClassificationResult(w, NodeClass.MASTER, false); + } else { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li - (int) (H / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + this.setColor(Color.CYAN); + + return new ClassificationResult(this.getNodeData().vi, NodeClass.SLAVE, false); + } + } + + return null; + } + + private boolean inclusionTest(List<Set<Integer>> U) { + Set<Integer> myVi = this.getNodeData().vi; + return U.stream().allMatch((data) -> { + return data.containsAll(myVi) || myVi.containsAll(data); + }); + } + + private NodeData getNodeData() { + return nodesDataMap.get(this.getID()); + } + + private void sendClassifierMessage() { + // MessageTimer msgTimer = new MessageTimer(new + // ClassifierMessage(this.getNodeData().li, this.getNodeData().vi)); + + if (this.isDefect()) { + int size = (int) (Math.random() * (Tools.getNodeList().size() - 1)); + + for (int i = 0; i < size; i++) { + this.send(new ClassifierMessage(this.getNodeData().li, this.getNodeData().vi), + Tools.getNodeList().getRandomNode()); + } + + } else { + for (Node node : Tools.getNodeList()) { + this.send(new ClassifierMessage(this.getNodeData().li, this.getNodeData().vi), node); + } + } + // msgTimer.startRelative(1, this); + } + + @Override + public void draw(Graphics g, PositionTransformation pt, boolean highlight) { + super.drawNodeAsDiskWithText(g, pt, highlight, this.toString(), 20, Color.white); + } + + @Override + public String toString() { + StringBuilder strBuilder = new StringBuilder(); + strBuilder.append("Li:" + this.getNodeData().li); + strBuilder.append(" | vi:" + Arrays.toString(this.getNodeData().vi.stream().toArray())); + strBuilder.append(" | Id:" + getID()); + strBuilder.append(" | decided:" + this.getNodeData().decided); + return strBuilder.toString(); + } + +} diff --git a/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/NodeData.java b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/NodeData.java new file mode 100644 index 0000000000000000000000000000000000000000..f71fb0a5043c4860e56079e1902aaa4e8b534810 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/NodeData.java @@ -0,0 +1,27 @@ +package projects.LA_Alpha.nodes.nodeImplementations; + +import java.util.Set; + +import lombok.Getter; +import lombok.Setter; + +public class NodeData { + @Getter + @Setter + Set<Integer> vi; + + @Getter + @Setter + Integer li; + + @Getter + @Setter + boolean decided; + + public NodeData(Set<Integer> vi, Integer li, boolean decided) { + this.vi = vi; + this.li = li; + this.decided = decided; + } + +} diff --git a/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/Nodestatus.java b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/Nodestatus.java new file mode 100644 index 0000000000000000000000000000000000000000..181dffdea2b4f4f952a5b6c689ab59485cfadf8b --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/Nodestatus.java @@ -0,0 +1,5 @@ +package projects.LA_Alpha.nodes.nodeImplementations; + +public enum Nodestatus { + AWAITING_RESPONSE, READY +} diff --git a/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/readme.txt b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..592548a64f91f3d014c824be21c45366c473b440 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/nodeImplementations/readme.txt @@ -0,0 +1 @@ +Place all your custom node implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Alpha/nodes/timers/readme.txt b/src/main/java/projects/LA_Alpha/nodes/timers/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..315e507d83d6bd6079f69f2b08c2e34b4f51acb7 --- /dev/null +++ b/src/main/java/projects/LA_Alpha/nodes/timers/readme.txt @@ -0,0 +1 @@ +Place all your custom timer implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/CustomGlobal.java b/src/main/java/projects/LA_Gamma/CustomGlobal.java new file mode 100644 index 0000000000000000000000000000000000000000..91c345fe1cdbef380a91bbec2f3589434b4318c0 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/CustomGlobal.java @@ -0,0 +1,111 @@ +/* +BSD 3-Clause License + +Copyright (c) 2007-2013, Distributed Computing Group (DCG) + ETH Zurich + Switzerland + dcg.ethz.ch + 2017-2018, André Brait + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package projects.LA_Gamma; + +import sinalgo.nodes.Node; +import sinalgo.runtime.AbstractCustomGlobal; +import sinalgo.tools.Tools; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.*; + +/** + * This class holds customized global state and methods for the framework. The + * only mandatory method to overwrite is <code>hasTerminated</code> <br> + * Optional methods to override are + * <ul> + * <li><code>customPaint</code></li> + * <li><code>handleEmptyEventQueue</code></li> + * <li><code>onExit</code></li> + * <li><code>preRun</code></li> + * <li><code>preRound</code></li> + * <li><code>postRound</code></li> + * <li><code>checkProjectRequirements</code></li> + * </ul> + * + * @see sinalgo.runtime.AbstractCustomGlobal for more details. <br> + * In addition, this class also provides the possibility to extend the + * framework with custom methods that can be called either through the menu + * or via a button that is added to the GUI. + */ +public class CustomGlobal extends AbstractCustomGlobal { + + @Override + public boolean hasTerminated() { + return false; + } + + /** + * An example of a method that will be available through the menu of the GUI. + */ + @AbstractCustomGlobal.GlobalMethod(menuText = "Echo") + public void echo() { + // Query the user for an input + String answer = JOptionPane.showInputDialog(null, "This is an example.\nType in any text to echo."); + // Show an information message + JOptionPane.showMessageDialog(null, "You typed '" + answer + "'", "Example Echo", + JOptionPane.INFORMATION_MESSAGE); + } + + /** + * An example to add a button to the user interface. In this sample, the button + * is labeled with a text 'GO'. Alternatively, you can specify an icon that is + * shown on the button. See AbstractCustomGlobal.CustomButton for more details. + */ + @AbstractCustomGlobal.CustomButton(buttonText = "GO", toolTipText = "A sample button") + public void sampleButton() { + JOptionPane.showMessageDialog(null, "You Pressed the 'GO' button."); + } + + /** + * Function for linking all the nodes together + */ + @AbstractCustomGlobal.GlobalMethod(menuText = "Link Everything") + public void linkEverything() { + List<Node> nodeList = new ArrayList<>(); + Tools.getNodeList().iterator().forEachRemaining(nodeList::add); + for (int i = 0; i < nodeList.size(); i++) { + for (int j = 0; j < nodeList.size(); j++) { + nodeList.get(i).addConnectionTo(nodeList.get((j))); + } + } + Tools.repaintGUI(); + } + +} diff --git a/src/main/java/projects/LA_Gamma/LogL.java b/src/main/java/projects/LA_Gamma/LogL.java new file mode 100644 index 0000000000000000000000000000000000000000..600ceb14c2d208f54da47adff0b36390207e4af1 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/LogL.java @@ -0,0 +1,44 @@ +/* +BSD 3-Clause License + +Copyright (c) 2007-2013, Distributed Computing Group (DCG) + ETH Zurich + Switzerland + dcg.ethz.ch + 2017-2018, André Brait + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package projects.LA_Gamma; + +/** + * Enumerates the log-levels. Levels above THRESHOLD will be included in the + * log-file. The levels below (with a higher enumeration value) not. + */ +public class LogL extends sinalgo.tools.logging.LogL { +} diff --git a/src/main/java/projects/LA_Gamma/models/connectivityModels/readme.txt b/src/main/java/projects/LA_Gamma/models/connectivityModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..693acbf0dcebaf9382c48dc7e2dd33db81f1e115 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/models/connectivityModels/readme.txt @@ -0,0 +1 @@ +Place all your custom connectivity models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/models/distributionModels/readme.txt b/src/main/java/projects/LA_Gamma/models/distributionModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..8aaa93d177444314a040160027c7a5fb1a1ec951 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/models/distributionModels/readme.txt @@ -0,0 +1 @@ +Place all your custom distribution models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/models/interferenceModels/readme.txt b/src/main/java/projects/LA_Gamma/models/interferenceModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..45b4a9aa80563296e90c13c667a740f4978c7614 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/models/interferenceModels/readme.txt @@ -0,0 +1 @@ +Place all your custom interference models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/models/messageTransmissionModels/readme.txt b/src/main/java/projects/LA_Gamma/models/messageTransmissionModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2dcde95a9f41a1b250f60a747329cbe85c6a87a --- /dev/null +++ b/src/main/java/projects/LA_Gamma/models/messageTransmissionModels/readme.txt @@ -0,0 +1 @@ +Place all your custom message transmission models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/models/mobilityModels/readme.txt b/src/main/java/projects/LA_Gamma/models/mobilityModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..d94bc8185176f050dfb80cac1938a41da6de560e --- /dev/null +++ b/src/main/java/projects/LA_Gamma/models/mobilityModels/readme.txt @@ -0,0 +1 @@ +Place all your custom mobility models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/models/reliabilityModels/readme.txt b/src/main/java/projects/LA_Gamma/models/reliabilityModels/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..0136e13d5229bb2b53470444ed3aef8259b00136 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/models/reliabilityModels/readme.txt @@ -0,0 +1 @@ +Place all your custom reliability models in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/nodes/edges/readme.txt b/src/main/java/projects/LA_Gamma/nodes/edges/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..97b95b0af0c06366834c779cc32961dfb2a964ad --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/edges/readme.txt @@ -0,0 +1 @@ +Place all your custom edge implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/nodes/messages/ClassificationResult.java b/src/main/java/projects/LA_Gamma/nodes/messages/ClassificationResult.java new file mode 100644 index 0000000000000000000000000000000000000000..d3cc1cf964b988f1f000eb485f929052666e836e --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/messages/ClassificationResult.java @@ -0,0 +1,27 @@ +package projects.LA_Gamma.nodes.messages; + +import java.util.Set; + +import lombok.Getter; +import lombok.Setter; + +public class ClassificationResult { + @Getter + @Setter + Set<Integer> nextRoundValue; + + @Getter + @Setter + NodeClass clazz; + + @Setter + @Getter + boolean decided; + + public ClassificationResult(Set<Integer> nextRoundValue, NodeClass clazz, boolean decided) { + this.nextRoundValue = nextRoundValue; + this.clazz = clazz; + this.decided = decided; + } + +} diff --git a/src/main/java/projects/LA_Gamma/nodes/messages/ClassifierMessage.java b/src/main/java/projects/LA_Gamma/nodes/messages/ClassifierMessage.java new file mode 100644 index 0000000000000000000000000000000000000000..6e35be01993dccefd6abc6b1570b63ee99248e21 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/messages/ClassifierMessage.java @@ -0,0 +1,23 @@ +package projects.LA_Gamma.nodes.messages; + +import java.util.HashSet; +import java.util.Set; + +import sinalgo.nodes.messages.Message; + +public class ClassifierMessage extends Message { + + Integer k; + Set<Integer> v; + + public ClassifierMessage(Integer k, Set<Integer> v) { + this.k = k; + this.v = v; + } + + @Override + public Message clone() { + return new ClassifierMessage(k, new HashSet<>(v)); + } + +} diff --git a/src/main/java/projects/LA_Gamma/nodes/messages/NodeClass.java b/src/main/java/projects/LA_Gamma/nodes/messages/NodeClass.java new file mode 100644 index 0000000000000000000000000000000000000000..356d088d46b05094e91bb63c739a51c78bf2b5a9 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/messages/NodeClass.java @@ -0,0 +1,5 @@ +package projects.LA_Gamma.nodes.messages; + +public enum NodeClass { + MASTER, SLAVE, UNDEFINED +} diff --git a/src/main/java/projects/LA_Gamma/nodes/messages/PhaseARequest.java b/src/main/java/projects/LA_Gamma/nodes/messages/PhaseARequest.java new file mode 100644 index 0000000000000000000000000000000000000000..2961a51a963bd0b9f661c86eee014cfa3aa4b2c1 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/messages/PhaseARequest.java @@ -0,0 +1,12 @@ +package projects.LA_Gamma.nodes.messages; + +import sinalgo.nodes.messages.Message; + +public class PhaseARequest extends Message { + + @Override + public Message clone() { + return new PhaseARequest(); + } + +} diff --git a/src/main/java/projects/LA_Gamma/nodes/messages/PhaseAResponse.java b/src/main/java/projects/LA_Gamma/nodes/messages/PhaseAResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..79db9271788b489eece5a5bbb2aa2a03b7f3edbc --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/messages/PhaseAResponse.java @@ -0,0 +1,22 @@ +package projects.LA_Gamma.nodes.messages; + +import java.util.HashSet; +import java.util.Set; + +import lombok.Getter; +import sinalgo.nodes.messages.Message; + +public class PhaseAResponse extends Message { + @Getter + Set<Integer> vi; + + public PhaseAResponse(Set<Integer> vi) { + this.vi = vi; + } + + @Override + public Message clone() { + return new PhaseAResponse(new HashSet<>(vi)); + } + +} diff --git a/src/main/java/projects/LA_Gamma/nodes/messages/readme.txt b/src/main/java/projects/LA_Gamma/nodes/messages/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..8baf37ab9d733601690609ba33829be49aaf3cbb --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/messages/readme.txt @@ -0,0 +1 @@ +Place all your custom message implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/ClassifierResponseMessages.java b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/ClassifierResponseMessages.java new file mode 100644 index 0000000000000000000000000000000000000000..123491102d137109b5a856af1ff8784a4e2bd65f --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/ClassifierResponseMessages.java @@ -0,0 +1,29 @@ +package projects.LA_Gamma.nodes.nodeImplementations; + +import java.util.HashSet; +import java.util.Set; + +import lombok.Getter; +import lombok.Setter; +import sinalgo.nodes.messages.Message; + +public class ClassifierResponseMessages extends Message { + + @Getter + @Setter + Set<Integer> vi; + + @Getter + @Setter + Integer li; + + public ClassifierResponseMessages(Set<Integer> vi, Integer li) { + this.vi = vi; + this.li = li; + } + + @Override + public Message clone() { + return new ClassifierResponseMessages(new HashSet<>(vi), li); + } +} diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/ClassifierSteps.java b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/ClassifierSteps.java new file mode 100644 index 0000000000000000000000000000000000000000..3f816dd75c81fc6c22f75b34a56ecfb114414112 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/ClassifierSteps.java @@ -0,0 +1,5 @@ +package projects.LA_Gamma.nodes.nodeImplementations; + +public enum ClassifierSteps { + SEND_MESSAGE, RECEIVE_MESSAGE +} diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/LA_GammaNode.java b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/LA_GammaNode.java new file mode 100644 index 0000000000000000000000000000000000000000..564a7337cd22036292b5bbb8225b24ab9476b85b --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/LA_GammaNode.java @@ -0,0 +1,253 @@ +package projects.LA_Gamma.nodes.nodeImplementations; + +import projects.LA_Gamma.nodes.messages.ClassificationResult; +import projects.LA_Gamma.nodes.messages.ClassifierMessage; +import projects.LA_Gamma.nodes.messages.NodeClass; +import projects.LA_Gamma.nodes.messages.PhaseARequest; +import projects.LA_Gamma.nodes.messages.PhaseAResponse; +import sinalgo.exception.WrongConfigurationException; +import sinalgo.gui.transformation.PositionTransformation; +import sinalgo.nodes.Node; +import sinalgo.nodes.messages.Inbox; +import sinalgo.nodes.messages.Message; +import sinalgo.tools.Tools; +import java.util.Map; +import java.util.Set; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.awt.Color; +import java.awt.Graphics; +import java.util.ArrayList; +import java.util.Arrays; + +public class LA_GammaNode extends Node { + + boolean defectNextRound = false; + + boolean defect = false; + + Phase currentPhase = Phase.A; + + int guess = 1; + + static Map<Long, NodeData> nodesDataMap = new HashMap<>(); + + @Override + public void handleMessages(Inbox inbox) { + List<ClassifierResponseMessages> classifierResponseMessages = new ArrayList<>(); + + List<PhaseAResponse> phaseAResponses = new ArrayList<>(); + + if (!defect) { + while (inbox.hasNext()) { + Message message = inbox.next(); + if (message instanceof ClassifierResponseMessages) { + classifierResponseMessages.add((ClassifierResponseMessages) message); + } else if (message instanceof ClassifierMessage) { + this.send(new ClassifierResponseMessages(this.getNodeData().vi, this.getNodeData().li), + inbox.getSender()); + } else if (message instanceof PhaseARequest) { + this.send(new PhaseAResponse(this.getNodeData().vi), inbox.getSender()); + } else if (message instanceof PhaseAResponse) { + phaseAResponses.add((PhaseAResponse) message); + } + } + + if (!classifierResponseMessages.isEmpty()) { + this.classifier(ClassifierSteps.RECEIVE_MESSAGE, classifierResponseMessages); + } + + if (!phaseAResponses.isEmpty()) { + this.endPhaseA(phaseAResponses); + } + + } + } + + @Override + public void preStep() { + if (this.currentPhase == Phase.A) { + this.startPhaseA(); + return; + } + + // phase B + if (!this.getNodeData().decided && !defect) { + this.guess *= 2; + + ClassificationResult res = this.classifier(ClassifierSteps.SEND_MESSAGE, null); + if (res == null) { + return; + } + if (res.isDecided()) { + this.getNodeData().decided = res.isDecided(); + this.getNodeData().vi = res.getNextRoundValue(); + } else if (res.getClazz() == NodeClass.MASTER) { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li + (int) (this.guess / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + } else { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li - (int) (this.guess / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + } + } + } + + @Override + public void init() { + Integer li = this.guess; + Integer setSize = (int) (Math.random() * (3 + 1)); + boolean decided = false; + Set<Integer> vi = new HashSet<Integer>(); + for (int i = 0; i < setSize; i++) { + Integer randomValue = (int) (Math.random() * (10000 + 1)); + vi.add(randomValue); + } + NodeData nodeData = new NodeData(vi, li, decided); + nodesDataMap.put(this.getID(), nodeData); + } + + @Override + public void neighborhoodChange() { + } + + @Override + public void postStep() { + if (defectNextRound) { + defect = true; + } else { + defect = false; + } + } + + @Override + public void checkRequirements() throws WrongConfigurationException { + } + + private ClassificationResult classifier(ClassifierSteps step, List<ClassifierResponseMessages> receivedMessages) { + if (step == ClassifierSteps.SEND_MESSAGE) { + this.sendClassifierMessage(); + return null; + } + + if (step == ClassifierSteps.RECEIVE_MESSAGE) { + List<Set<Integer>> U = new ArrayList<>(); + + for (int i = 0; i < receivedMessages.size(); i++) { + ClassifierResponseMessages currentMessage = receivedMessages.get(i); + U.add(currentMessage.vi); + } + + if (U.size() == 0 || this.inclusionTest(U)) { + this.getNodeData().decided = true; + return new ClassificationResult(nodesDataMap.get(this.getID()).vi, NodeClass.UNDEFINED, true); + } + + Set<Integer> w = new HashSet<>(); + + for (Set<Integer> x : U) { + w.addAll(x); + } + + Integer h_w = w.size(); + this.getNodeData().li = this.guess; + Integer k = this.getNodeData().li; + + if (h_w > k) { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li + (int) (this.guess / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + this.setColor(Color.green); + this.getNodeData().vi = new HashSet<>(w); + + return new ClassificationResult(w, NodeClass.MASTER, false); + } else { + int r = Tools.getRuntime().getNumberOfRounds(); + Integer li_ = this.getNodeData().li - (int) (this.guess / Math.pow(2, r + 1)); + this.getNodeData().li = li_; + this.setColor(Color.CYAN); + + return new ClassificationResult(this.getNodeData().vi, NodeClass.SLAVE, false); + } + } + + return null; + } + + private boolean inclusionTest(List<Set<Integer>> U) { + Set<Integer> myVi = this.getNodeData().vi; + return U.stream().allMatch((data) -> { + return data.containsAll(myVi) || myVi.containsAll(data); + }); + } + + private NodeData getNodeData() { + return nodesDataMap.get(this.getID()); + } + + private void startPhaseA() { + this.getOutgoingConnections().iterator().forEachRemaining((e) -> { + this.send(new PhaseARequest(), e.getEndNode()); + }); + } + + private void endPhaseA(List<PhaseAResponse> responses) { + Set<Integer> newVi = new HashSet<>(); + + for (PhaseAResponse response : responses) { + newVi.addAll(response.getVi()); + } + + this.getNodeData().vi = new HashSet<>(newVi); + this.currentPhase = Phase.B; + } + + private void sendClassifierMessage() { + // MessageTimer msgTimer = new MessageTimer(new + // ClassifierMessage(this.getNodeData().li, this.getNodeData().vi)); + + if (defectNextRound || defect) { + int size = (int) (Math.random() * (Tools.getNodeList().size() - 1)); + + for (int i = 0; i < size; i++) { + this.send(new ClassifierMessage(this.getNodeData().li, this.getNodeData().vi), + Tools.getNodeList().getRandomNode()); + } + + } else { + for (Node node : Tools.getNodeList()) { + this.send(new ClassifierMessage(this.getNodeData().li, this.getNodeData().vi), node); + } + } + // msgTimer.startRelative(1, this); + } + + @Override + public void draw(Graphics g, PositionTransformation pt, boolean highlight) { + super.drawNodeAsDiskWithText(g, pt, highlight, this.toString(), 20, Color.white); + } + + @Override + public String toString() { + StringBuilder strBuilder = new StringBuilder(); + strBuilder.append("Li:" + this.getNodeData().li); + strBuilder.append(" | vi:" + Arrays.toString(this.getNodeData().vi.stream().toArray())); + strBuilder.append(" | Id:" + getID()); + strBuilder.append(" | decided:" + this.getNodeData().decided); + return strBuilder.toString(); + } + + @NodePopupMethod(menuText = "Toggle Defect Node") + public void togleDefect() { + if (defectNextRound) { + defectNextRound = false; + this.setColor(Color.black); + } else { + defectNextRound = true; + this.setColor(Color.red); + } + } + +} diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/NodeData.java b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/NodeData.java new file mode 100644 index 0000000000000000000000000000000000000000..eef7cdb5cee6462a1b3c011127b4538c709ea9ad --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/NodeData.java @@ -0,0 +1,27 @@ +package projects.LA_Gamma.nodes.nodeImplementations; + +import java.util.Set; + +import lombok.Getter; +import lombok.Setter; + +public class NodeData { + @Getter + @Setter + Set<Integer> vi; + + @Getter + @Setter + Integer li; + + @Getter + @Setter + boolean decided; + + public NodeData(Set<Integer> vi, Integer li, boolean decided) { + this.vi = vi; + this.li = li; + this.decided = decided; + } + +} diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/Nodestatus.java b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/Nodestatus.java new file mode 100644 index 0000000000000000000000000000000000000000..8e0a1225131103bde7b43f822c1e3b8e5b654c15 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/Nodestatus.java @@ -0,0 +1,5 @@ +package projects.LA_Gamma.nodes.nodeImplementations; + +public enum Nodestatus { + AWAITING_RESPONSE, READY +} diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/Phase.java b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/Phase.java new file mode 100644 index 0000000000000000000000000000000000000000..0c9623c56338fa47e03d51cbf577e0af168d9c9c --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/Phase.java @@ -0,0 +1,5 @@ +package projects.LA_Gamma.nodes.nodeImplementations; + +public enum Phase { + A, B, LA_Alpha +} diff --git a/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/readme.txt b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..592548a64f91f3d014c824be21c45366c473b440 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/nodeImplementations/readme.txt @@ -0,0 +1 @@ +Place all your custom node implementations in this folder. \ No newline at end of file diff --git a/src/main/java/projects/LA_Gamma/nodes/timers/readme.txt b/src/main/java/projects/LA_Gamma/nodes/timers/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..315e507d83d6bd6079f69f2b08c2e34b4f51acb7 --- /dev/null +++ b/src/main/java/projects/LA_Gamma/nodes/timers/readme.txt @@ -0,0 +1 @@ +Place all your custom timer implementations in this folder. \ No newline at end of file diff --git a/src/main/java/sinalgo/nodes/edges/Edge.java b/src/main/java/sinalgo/nodes/edges/Edge.java index 7d34a80ec18a363451d994676241f37d3cb2bbce..82421edded2a9894484055785fbd00f5b22197fe 100644 --- a/src/main/java/sinalgo/nodes/edges/Edge.java +++ b/src/main/java/sinalgo/nodes/edges/Edge.java @@ -66,7 +66,7 @@ import java.lang.reflect.InvocationTargetException; * All edges of this framework are unidirectional. The bidirectional edges just * ensure that there is an edge object in both directions. */ -@EqualsAndHashCode(of = {"startNode", "endNode"}) +@EqualsAndHashCode(of = { "startNode", "endNode" }) public class Edge implements DoublyLinkedListEntry { /** @@ -115,7 +115,8 @@ public class Edge implements DoublyLinkedListEntry { Edge oe = this.getOppositeEdge(); this.setOppositeEdge(null); oe.setOppositeEdge(null); // set unlink oppositeEdges to avoid loops - this.getEndNode().getOutgoingConnections().remove(this.getEndNode(), this.getStartNode()); // remove the opposite edge + this.getEndNode().getOutgoingConnections().remove(this.getEndNode(), this.getStartNode()); // remove the + // opposite edge oe.free(); } } @@ -261,7 +262,7 @@ public class Edge implements DoublyLinkedListEntry { * inactive edge does not overpaint an active edge. * * @return The edge that connects the two end nodes of this edge in the other - * direction. Null if there is no such edge. + * direction. Null if there is no such edge. */ @Getter @Setter @@ -325,7 +326,8 @@ public class Edge implements DoublyLinkedListEntry { */ protected final void findOppositeEdge() { for (Edge e : this.endNode.getOutgoingConnections()) { - if ((e.getStartNode().getID() == this.endNode.getID()) && (e.getEndNode().getID() == this.startNode.getID())) { + if ((e.getStartNode().getID() == this.endNode.getID()) + && (e.getEndNode().getID() == this.startNode.getID())) { this.setOppositeEdge(e); e.setOppositeEdge(this); return; @@ -347,7 +349,8 @@ public class Edge implements DoublyLinkedListEntry { * * @param xCoord The x coordinate of the position on the screen * @param yCoord The y coordinate of the position on the screen - * @param pt The transformation object used to translate between logic and gui + * @param pt The transformation object used to translate between logic and + * gui * coordinates. * @return True if this edge covers the given position, otherwise false. */ @@ -436,12 +439,15 @@ public class Edge implements DoublyLinkedListEntry { } edge = (Edge) constructor.newInstance(); } catch (ClassNotFoundException cNFE) { - throw new SinalgoFatalException("The implementation of the edge '" + nameOfSearchedEdge + "' could not be found.\n" - + "Change the Type in the XML-File or implement it." + ""); + throw new SinalgoFatalException( + "The implementation of the edge '" + nameOfSearchedEdge + "' could not be found.\n" + + "Change the Type in the XML-File or implement it." + ""); } catch (IllegalArgumentException | SecurityException | IllegalAccessException | InstantiationException e) { - throw new SinalgoFatalException("Exception caught while creating edge '" + nameOfSearchedEdge + "'.\n" + e); + throw new SinalgoFatalException( + "Exception caught while creating edge '" + nameOfSearchedEdge + "'.\n" + e); } catch (InvocationTargetException e) { - throw new SinalgoFatalException("Exception caught while creating edge '" + nameOfSearchedEdge + "'.\n" + e.getCause()); + throw new SinalgoFatalException( + "Exception caught while creating edge '" + nameOfSearchedEdge + "'.\n" + e.getCause()); } catch (NoSuchMethodException e) { throw new SinalgoFatalException("Cannot instanciate an edge of type '" + nameOfSearchedEdge + "' for two nodes of type \n(" + from.getClass().getName() + ", " + to.getClass().getName() diff --git a/src/main/resources/projects/LA_Alpha/Config.xml b/src/main/resources/projects/LA_Alpha/Config.xml new file mode 100644 index 0000000000000000000000000000000000000000..161daae9e7fb51cec43feeb4d20c46bec2bdf476 --- /dev/null +++ b/src/main/resources/projects/LA_Alpha/Config.xml @@ -0,0 +1,257 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Document> + <Framework> + <!--*********************************************************************** --> + <!-- Simulation Area --> + <!--*********************************************************************** --> + <!--Number of dimensions (2 for 2D, 3 for 3D) --> + <dimensions value="2"/> + + <!--Length of the deployment field along the x-axis. --> + <dimX value="5000"/> + + <!--Length of the deployment field along the y-axis. --> + <dimY value="5000"/> + + <!--Length of the deployment field along the z-axis. --> + <dimZ value="500"/> + + <!--*********************************************************************** --> + <!-- Simulation --> + <!--*********************************************************************** --> + <!--Switches between synchronous and asynchronous mode. --> + <asynchronousMode value="false"/> + + <!--If set to true, the runtime obtains for each node a new position from + the mobility model at the beginning of each round. This flag needs to be + turned on if the chosen mobility model of any node may change the node's + position. Set this flag to FALSE for static graphs whose nodes do never change + their position to increase performance. --> + <mobility value="false"/> + + <!--If set to true, the chosen interference model is called at the end + of every round to test for interferring packets. To increase performance, + set this flag to FALSE if you do not consider interference. --> + <interference value="false"/> + + <!--Set this flag to true if interference only decreases if less messages + are being sent and increases if more messages are being sent. This flag enables + considerable optimizations. --> + <interferenceIsAdditive value="true"/> + + <!--Set this flag to true if a node can receive messages while it is sending + messages itself, otherwise to false. This flag is only relevant if interference + is turned on, and it must be handled properly in the used interference model. --> + <canReceiveWhileSending value="true"/> + + <!--The default type of edges to be used --> + <edgeType value="sinalgo.nodes.edges.Edge"/> + + <!--If set to true, the application exits as soon as the termination criteria + is met. This flag only affects the GUI mode. --> + <exitOnTerminationInGUI value="false"/> + + <!--If set true, in asynchronous mode the connections are initialized before + the first event executes. Note that this flag is useless in synchronous mode + as the connections are updated in every step anyway. --> + <initializeConnectionsOnStartup value="false"/> + + <!--Defines how often the GUI is updated. The GUI is redrawn after every + refreshRate-th round. --> + <refreshRate value="1"/> + + <!--*********************************************************************** --> + <!-- Random number generators --> + <!--*********************************************************************** --> + <!--If set to true, the random number generators of the framework use a + fixed seed. --> + <useFixedSeed value="false"/> + + <!--The seed to be used by the random number generators if useFixedSeed + is set to true. --> + <fixedSeed value="77654767234"/> + + <!--*********************************************************************** --> + <!-- Logging --> + <!--*********************************************************************** --> + <!--Name of the default log file, used by the system, but also for use + by the end-user. (This log file is stored under sinalgo.runtime.Global.log.) --> + <logFileName value="logfile.txt"/> + + <!--Redirects the default log file to the console. No logfile will be created + if set to true. --> + <outputToConsole value="true"/> + + <!--Indicates whether all log-files of the current simulation are stored + in a new directory. The name of the new directory is given by the string-representation + of the date when the simulation starts. --> + <logToTimeDirectory value="true"/> + + <!--If set to true, the system configuration is written to the default + log file after the application has been started. --> + <logConfiguration value="true"/> + + <!--If set to true, the log files are flushed every time a new log is added. --> + <eagerFlush value="false"/> + + <!--*********************************************************************** --> + <!-- GUI --> + <!--*********************************************************************** --> + <!--If true, the application shows an extended control panel. --> + <extendedControl value="true"/> + + <!--If true, the graph edges are drawn as directed arrows, otherwise simple + lines. --> + <drawArrows value="true"/> + + <!--Fraction of the old and new zoom values for a zoom step. --> + <zoomStep value="1.2"/> + + <!--Fraction of the old and new zoom values for a zoom step when zooming + with the mouse wheel. --> + <wheelZoomStep value="1.05"/> + + <!--The minimum required zoom --> + <minZoomFactor value="0.05"/> + + <!--If set to true, the nodes are ordered according to their elevation + before drawing, such that nodes closer to the viewer are drawn on top. This + setting only applies to 3D. --> + <draw3DGraphNodesInProperOrder value="true"/> + + <!--If set to true and in 3D mode, the cube is drawn with perspective. --> + <usePerspectiveView value="true"/> + + <!--Factor that defines the distance of the observer from the cube when + useing the perspective view in 3D. Default: 30 --> + <perspectiveViewDistance value="40"/> + + <!--*********************************************************************** --> + <!-- Background map in 2D --> + <!--*********************************************************************** --> + <!--If set to true, the background of a 2D simulation is colored according + to a map, specified in a map-file, specified by the field map --> + <useMap value="false"/> + + <!--In 2D, the background can be colored depending on a map file. This + field contains the file name for this map, which is supposed to be located + in the source folder of the current project. The map is only painted if useMap + is set to true. --> + <map value="images/map.jpg"/> + + <!--*********************************************************************** --> + <!-- Models --> + <!--*********************************************************************** --> + <!--The message transmission model used when none is specified --> + <defaultMessageTransmissionModel + value="ConstantTime"/> + + <!--Default connectivity model used when none is specified --> + <defaultConnectivityModel value="StaticConnectivity"/> + + <!--Default distribution model used when none is specified --> + <defaultDistributionModel value="Circle"/> + + <!--Default interference model used when none is specified --> + <defaultInterferenceModel value="NoInterference"/> + + <!--Default mobility model used when none is specified --> + <defaultMobilityModel value="NoMobility"/> + + <!--Default reliability model used when none is specified --> + <defaultReliabilityModel value="ReliableDelivery"/> + + <!--Default node implementation used when none is specified --> + <defaultNodeImplementation value="LA_Alpha:LA_AlphaNode"/> + + <!--*********************************************************************** --> + <!-- Node storage, position transformation --> + <!--*********************************************************************** --> + <!--Transformation implementation for 2D. (This is used to translate between + the logic positions used by the simulation to the 2D coordinate system used + by the GUI to display the graph) --> + <guiPositionTransformation2D + value="sinalgo.gui.transformation.Transformation2D"/> + + <!--Transformation implementation for 3D. (This is used to translate between + the logic positions used by the simulation to the 2D coordinate system used + by the GUI to display the graph) --> + <guiPositionTransformation3D + value="sinalgo.gui.transformation.Transformation3D"/> + + <!--Node collection implementation for 2D. --> + <nodeCollection2D + value="sinalgo.runtime.nodeCollection.Geometric2DNodeCollection"/> + + <!--Node collection implementation for 3D. --> + <nodeCollection3D + value="sinalgo.runtime.nodeCollection.Geometric3DNodeCollection"/> + + <!--*********************************************************************** --> + <!-- Diverse Settings --> + <!--*********************************************************************** --> + <!--Show hints on how to further optimize the simulation when some parameters + seem not to be set optimally. --> + <showOptimizationHints value="true"/> + + <!--Indicates whether the edges are drawn in the default draw implementation + for the graph. --> + <drawEdges value="true"/> + + <!--Indicates whether the nodes are drawn in the default draw implementation + for the graph. --> + <drawNodes value="true"/> + + <!--The number of future events that are shown in the control panel --> + <shownEventQueueSize value="10"/> + + <!--The length of the arrows. This length is multiplied by the actualzoomLevel. --> + <arrowLength value="8"/> + + <!--The width of the arrows. This width is multiplied by the actualzoomLevel. --> + <arrowWidth value="1"/> + + <!--The dsfault value of the rounds field. --> + <defaultRoundNumber value="1"/> + + <!--EPS 2 PDF command: This is the command that is used to convert an EPS + file into a PDF file. You can use the following parameters: %s is the complete + path from the root folder of the framework to the SOURCE file (the eps) %t + is the complete path from the root folder of the framework to the TARGET + file (the pdf) These placeholders are set by the framework. Example: 'epstopdf + %s') --> + <epsToPdfCommand value="epstopdf %s"/> + + <!--Indicates whether the background in the ps should be white or gray. + The gray version is easier to understand (especially in 3D) but the white + one should be more useful to be imported in reports. --> + <epsDrawBackgroundWhite value="true"/> + + </Framework> + <Custom> + <MessageTransmission ConstantTime="1"/> + + <Node defaultSize="10"/> + + <GeometricNodeCollection rMax="100"/> + + <UDG rMax="100"/> + + <SINR alpha="2" beta="0.7" noise="0"/> + + <RandomWayPoint> + <Speed distribution="Gaussian" mean="10" variance="20"/> + <WaitingTime distribution="Poisson" lambda="10"/> + </RandomWayPoint> + + <RandomDirection> + <NodeSpeed distribution="Gaussian" mean="10" variance="20"/> + <WaitingTime distribution="Poisson" lambda="10"/> + <MoveTime distribution="Uniform" min="5" max="20"/> + </RandomDirection> + + <QUDG rMin="30" rMax="50" ProbabilityType="constant" + connectionProbability="0.6"/> + </Custom> +</Document> + diff --git a/src/main/resources/projects/LA_Alpha/description.txt b/src/main/resources/projects/LA_Alpha/description.txt new file mode 100644 index 0000000000000000000000000000000000000000..fcffa4ef01a4e45b7946c16c68a83f56a2205ab2 --- /dev/null +++ b/src/main/resources/projects/LA_Alpha/description.txt @@ -0,0 +1,7 @@ +This project is the implementation of a simple election algorithm for circular unidirectional graphs + +1) select the `Circular Simple Election` project +2) simulation > generate nodes > set the number of nodes and the distribution model > choose the NodeImpl for Node implementation > set the connectivity to static > No interference > No mobility > reliable delivery > click OK +3) Global > Link Circular +4) right click any node and click Start Election +5) start the simulation and diff --git a/src/main/resources/projects/LA_Alpha/images/readme.txt b/src/main/resources/projects/LA_Alpha/images/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..c68ecfa633e8ab1fc3c55143d53a4ecfa5d09f69 --- /dev/null +++ b/src/main/resources/projects/LA_Alpha/images/readme.txt @@ -0,0 +1 @@ +This folder contains the images for the user-defined buttons. \ No newline at end of file diff --git a/src/main/resources/projects/LA_Gamma/Config.xml b/src/main/resources/projects/LA_Gamma/Config.xml new file mode 100644 index 0000000000000000000000000000000000000000..2f7bc0878774e6705234d3eb5521845712dcd6d8 --- /dev/null +++ b/src/main/resources/projects/LA_Gamma/Config.xml @@ -0,0 +1,257 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Document> + <Framework> + <!--*********************************************************************** --> + <!-- Simulation Area --> + <!--*********************************************************************** --> + <!--Number of dimensions (2 for 2D, 3 for 3D) --> + <dimensions value="2"/> + + <!--Length of the deployment field along the x-axis. --> + <dimX value="2000"/> + + <!--Length of the deployment field along the y-axis. --> + <dimY value="2000"/> + + <!--Length of the deployment field along the z-axis. --> + <dimZ value="500"/> + + <!--*********************************************************************** --> + <!-- Simulation --> + <!--*********************************************************************** --> + <!--Switches between synchronous and asynchronous mode. --> + <asynchronousMode value="false"/> + + <!--If set to true, the runtime obtains for each node a new position from + the mobility model at the beginning of each round. This flag needs to be + turned on if the chosen mobility model of any node may change the node's + position. Set this flag to FALSE for static graphs whose nodes do never change + their position to increase performance. --> + <mobility value="false"/> + + <!--If set to true, the chosen interference model is called at the end + of every round to test for interferring packets. To increase performance, + set this flag to FALSE if you do not consider interference. --> + <interference value="false"/> + + <!--Set this flag to true if interference only decreases if less messages + are being sent and increases if more messages are being sent. This flag enables + considerable optimizations. --> + <interferenceIsAdditive value="true"/> + + <!--Set this flag to true if a node can receive messages while it is sending + messages itself, otherwise to false. This flag is only relevant if interference + is turned on, and it must be handled properly in the used interference model. --> + <canReceiveWhileSending value="true"/> + + <!--The default type of edges to be used --> + <edgeType value="sinalgo.nodes.edges.Edge"/> + + <!--If set to true, the application exits as soon as the termination criteria + is met. This flag only affects the GUI mode. --> + <exitOnTerminationInGUI value="false"/> + + <!--If set true, in asynchronous mode the connections are initialized before + the first event executes. Note that this flag is useless in synchronous mode + as the connections are updated in every step anyway. --> + <initializeConnectionsOnStartup value="false"/> + + <!--Defines how often the GUI is updated. The GUI is redrawn after every + refreshRate-th round. --> + <refreshRate value="1"/> + + <!--*********************************************************************** --> + <!-- Random number generators --> + <!--*********************************************************************** --> + <!--If set to true, the random number generators of the framework use a + fixed seed. --> + <useFixedSeed value="false"/> + + <!--The seed to be used by the random number generators if useFixedSeed + is set to true. --> + <fixedSeed value="77654767234"/> + + <!--*********************************************************************** --> + <!-- Logging --> + <!--*********************************************************************** --> + <!--Name of the default log file, used by the system, but also for use + by the end-user. (This log file is stored under sinalgo.runtime.Global.log.) --> + <logFileName value="logfile.txt"/> + + <!--Redirects the default log file to the console. No logfile will be created + if set to true. --> + <outputToConsole value="true"/> + + <!--Indicates whether all log-files of the current simulation are stored + in a new directory. The name of the new directory is given by the string-representation + of the date when the simulation starts. --> + <logToTimeDirectory value="true"/> + + <!--If set to true, the system configuration is written to the default + log file after the application has been started. --> + <logConfiguration value="true"/> + + <!--If set to true, the log files are flushed every time a new log is added. --> + <eagerFlush value="false"/> + + <!--*********************************************************************** --> + <!-- GUI --> + <!--*********************************************************************** --> + <!--If true, the application shows an extended control panel. --> + <extendedControl value="true"/> + + <!--If true, the graph edges are drawn as directed arrows, otherwise simple + lines. --> + <drawArrows value="true"/> + + <!--Fraction of the old and new zoom values for a zoom step. --> + <zoomStep value="1.2"/> + + <!--Fraction of the old and new zoom values for a zoom step when zooming + with the mouse wheel. --> + <wheelZoomStep value="1.05"/> + + <!--The minimum required zoom --> + <minZoomFactor value="0.05"/> + + <!--If set to true, the nodes are ordered according to their elevation + before drawing, such that nodes closer to the viewer are drawn on top. This + setting only applies to 3D. --> + <draw3DGraphNodesInProperOrder value="true"/> + + <!--If set to true and in 3D mode, the cube is drawn with perspective. --> + <usePerspectiveView value="true"/> + + <!--Factor that defines the distance of the observer from the cube when + useing the perspective view in 3D. Default: 30 --> + <perspectiveViewDistance value="40"/> + + <!--*********************************************************************** --> + <!-- Background map in 2D --> + <!--*********************************************************************** --> + <!--If set to true, the background of a 2D simulation is colored according + to a map, specified in a map-file, specified by the field map --> + <useMap value="false"/> + + <!--In 2D, the background can be colored depending on a map file. This + field contains the file name for this map, which is supposed to be located + in the source folder of the current project. The map is only painted if useMap + is set to true. --> + <map value="images/map.jpg"/> + + <!--*********************************************************************** --> + <!-- Models --> + <!--*********************************************************************** --> + <!--The message transmission model used when none is specified --> + <defaultMessageTransmissionModel + value="ConstantTime"/> + + <!--Default connectivity model used when none is specified --> + <defaultConnectivityModel value="StaticConnectivity"/> + + <!--Default distribution model used when none is specified --> + <defaultDistributionModel value="Circle"/> + + <!--Default interference model used when none is specified --> + <defaultInterferenceModel value="NoInterference"/> + + <!--Default mobility model used when none is specified --> + <defaultMobilityModel value="NoMobility"/> + + <!--Default reliability model used when none is specified --> + <defaultReliabilityModel value="ReliableDelivery"/> + + <!--Default node implementation used when none is specified --> + <defaultNodeImplementation value="LA_Gamma:LA_GammaNode"/> + + <!--*********************************************************************** --> + <!-- Node storage, position transformation --> + <!--*********************************************************************** --> + <!--Transformation implementation for 2D. (This is used to translate between + the logic positions used by the simulation to the 2D coordinate system used + by the GUI to display the graph) --> + <guiPositionTransformation2D + value="sinalgo.gui.transformation.Transformation2D"/> + + <!--Transformation implementation for 3D. (This is used to translate between + the logic positions used by the simulation to the 2D coordinate system used + by the GUI to display the graph) --> + <guiPositionTransformation3D + value="sinalgo.gui.transformation.Transformation3D"/> + + <!--Node collection implementation for 2D. --> + <nodeCollection2D + value="sinalgo.runtime.nodeCollection.Geometric2DNodeCollection"/> + + <!--Node collection implementation for 3D. --> + <nodeCollection3D + value="sinalgo.runtime.nodeCollection.Geometric3DNodeCollection"/> + + <!--*********************************************************************** --> + <!-- Diverse Settings --> + <!--*********************************************************************** --> + <!--Show hints on how to further optimize the simulation when some parameters + seem not to be set optimally. --> + <showOptimizationHints value="true"/> + + <!--Indicates whether the edges are drawn in the default draw implementation + for the graph. --> + <drawEdges value="true"/> + + <!--Indicates whether the nodes are drawn in the default draw implementation + for the graph. --> + <drawNodes value="true"/> + + <!--The number of future events that are shown in the control panel --> + <shownEventQueueSize value="10"/> + + <!--The length of the arrows. This length is multiplied by the actualzoomLevel. --> + <arrowLength value="8"/> + + <!--The width of the arrows. This width is multiplied by the actualzoomLevel. --> + <arrowWidth value="1"/> + + <!--The dsfault value of the rounds field. --> + <defaultRoundNumber value="1"/> + + <!--EPS 2 PDF command: This is the command that is used to convert an EPS + file into a PDF file. You can use the following parameters: %s is the complete + path from the root folder of the framework to the SOURCE file (the eps) %t + is the complete path from the root folder of the framework to the TARGET + file (the pdf) These placeholders are set by the framework. Example: 'epstopdf + %s') --> + <epsToPdfCommand value="epstopdf %s"/> + + <!--Indicates whether the background in the ps should be white or gray. + The gray version is easier to understand (especially in 3D) but the white + one should be more useful to be imported in reports. --> + <epsDrawBackgroundWhite value="true"/> + + </Framework> + <Custom> + <MessageTransmission ConstantTime="1"/> + + <Node defaultSize="10"/> + + <GeometricNodeCollection rMax="100"/> + + <UDG rMax="100"/> + + <SINR alpha="2" beta="0.7" noise="0"/> + + <RandomWayPoint> + <Speed distribution="Gaussian" mean="10" variance="20"/> + <WaitingTime distribution="Poisson" lambda="10"/> + </RandomWayPoint> + + <RandomDirection> + <NodeSpeed distribution="Gaussian" mean="10" variance="20"/> + <WaitingTime distribution="Poisson" lambda="10"/> + <MoveTime distribution="Uniform" min="5" max="20"/> + </RandomDirection> + + <QUDG rMin="30" rMax="50" ProbabilityType="constant" + connectionProbability="0.6"/> + </Custom> +</Document> + diff --git a/src/main/resources/projects/LA_Gamma/description.txt b/src/main/resources/projects/LA_Gamma/description.txt new file mode 100644 index 0000000000000000000000000000000000000000..fcffa4ef01a4e45b7946c16c68a83f56a2205ab2 --- /dev/null +++ b/src/main/resources/projects/LA_Gamma/description.txt @@ -0,0 +1,7 @@ +This project is the implementation of a simple election algorithm for circular unidirectional graphs + +1) select the `Circular Simple Election` project +2) simulation > generate nodes > set the number of nodes and the distribution model > choose the NodeImpl for Node implementation > set the connectivity to static > No interference > No mobility > reliable delivery > click OK +3) Global > Link Circular +4) right click any node and click Start Election +5) start the simulation and diff --git a/src/main/resources/projects/LA_Gamma/images/readme.txt b/src/main/resources/projects/LA_Gamma/images/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..c68ecfa633e8ab1fc3c55143d53a4ecfa5d09f69 --- /dev/null +++ b/src/main/resources/projects/LA_Gamma/images/readme.txt @@ -0,0 +1 @@ +This folder contains the images for the user-defined buttons. \ No newline at end of file diff --git a/src/main/resources/projects/circularSimpleElection/description.txt b/src/main/resources/projects/circularSimpleElection/description.txt index 65bb4574a5135ea08e70750aa254c21c0a80873d..fcffa4ef01a4e45b7946c16c68a83f56a2205ab2 100644 --- a/src/main/resources/projects/circularSimpleElection/description.txt +++ b/src/main/resources/projects/circularSimpleElection/description.txt @@ -1,7 +1,7 @@ -This is the template project. +This project is the implementation of a simple election algorithm for circular unidirectional graphs -Copy this folder and rename it to start a new project. If this description -appears for a project that is not the template description then the -description has not yet been written. Please describe the project in -the description.txt stored in the project root folder of this -project. \ No newline at end of file +1) select the `Circular Simple Election` project +2) simulation > generate nodes > set the number of nodes and the distribution model > choose the NodeImpl for Node implementation > set the connectivity to static > No interference > No mobility > reliable delivery > click OK +3) Global > Link Circular +4) right click any node and click Start Election +5) start the simulation and