From 691ebc9c9946a6e450ca6ab88f9d2ffbc7db099d Mon Sep 17 00:00:00 2001
From: Philipp Spohr <spohr.philipp@web.de>
Date: Mon, 11 Dec 2017 10:01:42 +0100
Subject: [PATCH] Basic CyRest support for core algorithm

---
 .../de/hhu/ba/yoshikoWrapper/CyActivator.java |  2 +-
 .../ba/yoshikoWrapper/core/ParameterSet.java  | 39 ++++++++++++++-----
 .../cytoUtil/GraphAnalyzer.java               | 15 +++++--
 .../taskFactories/YoshikoCommand.java         |  3 ++
 .../yoshikoWrapper/tasks/AlgorithmTask.java   |  4 +-
 5 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java
index a228110..02bcee9 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java
@@ -117,7 +117,7 @@ public class CyActivator extends AbstractCyActivator {
 		Properties props = new Properties();
 		props.setProperty(COMMAND_NAMESPACE, "yoshiko");
 		props.setProperty(COMMAND, YoshikoCommand.PERFORM_ALGORITHM.toString());
-		props.setProperty(COMMAND_DESCRIPTION,"TEST PERFORM ALGORITHM");
+		props.setProperty(COMMAND_DESCRIPTION,"Cluster a network with the Yoshiko algorithm");
 		registerService(context, commandTaskFactory, TaskFactory.class, props);
 
 		//Initialize and register main panel
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
index 753d5bb..79d7daa 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
@@ -8,21 +8,40 @@ public class ParameterSet {
 
 	@Tunable(description="Time Limit for the ILP mode", context="nogui")
 	public int timeLimit = -1;
+
 	@Tunable(description="A column in the edge table containing weights", context="nogui")
 	public CyColumn weightColumn;
-
+	@Tunable(description="A column containing boolean entries for edges that are to be treated as permanent",context="nogui")
 	public CyColumn permanentColumn;
+	@Tunable(description="A column containing boolean entries for edges that are to be treated as forbidden",context="nogui")
 	public CyColumn forbiddenColumn;
-	public double defaultInsertionCost;
-	public double defaultDeletionCost;
-	public String reductionRulesBitMask;
-	public double snrMultFactor;
-	public boolean useTriangleCuts;
-	public boolean usePartitionCuts;
-	public boolean useHeuristic;
-	public int solCount;
+
+	@Tunable(description="The default insertion cost that is to be used for non-existing edges",context="nogui")
+	public double defaultInsertionCost = -1;
+	@Tunable(description="The default deletion cost that is to be used for edges without an associated weight",context="nogui")
+	public double defaultDeletionCost = 1;
+
+	@Tunable(description="A bitmask representing which reduction rules should be used",context="nogui") //TODO: Filter bad bitmasks
+	public String reductionRulesBitMask = "000000";
+	@Tunable(description="A value controlling the resolution of the SNR reduction rule. Higher values mean a longer running time but possibly better reduction.",context="nogui")
+	public double snrMultFactor = 1.0;
+
+	@Tunable(description="Alternative Callback for CPLEX, might be faster on certain instances",context="nogui")
+	public boolean useTriangleCuts = false;
+	@Tunable(description="Alternative Callback for CPLEX, might be faster on large instances",context="nogui")
+	public boolean usePartitionCuts = false;
+
+	@Tunable(description="Uses a heuristic instead of ILP to solve WCE, significantly faster",context="nogui")
+	public boolean useHeuristic = true;
+
+	@Tunable(description="The maximum number of (optimal) solutions that is to be calculated",context="nogui")
+	public int solCount = 1;
+
+	@Tunable(description="Disable multithreading to keep the system responsive",context="nogui")
 	public boolean disableMultiThreading;
+
+	@Tunable(description="Automatically choose an appopriate set of reduction rules (overrides a given bitmask)",context="nogui")
 	/**Describes whether auto configuration of the reduction rules is to be used. Overrides the bit mask.**/
-	public boolean suggestReduction;
+	public boolean suggestReduction = true;
 
 }
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/GraphAnalyzer.java b/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/GraphAnalyzer.java
index 51c1daf..c600391 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/GraphAnalyzer.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/cytoUtil/GraphAnalyzer.java
@@ -6,14 +6,14 @@ import org.cytoscape.model.CyColumn;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyRow;
-import org.slf4j.Logger;
+//import org.slf4j.Logger;
 
-import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
+//import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
 
 
 public class GraphAnalyzer {
 
-	private static Logger logger = YoshikoLogger.getInstance().getLogger();
+	//private static Logger logger = YoshikoLogger.getInstance().getLogger();
 
 	public static boolean isMultiGraph(CyNetwork net) {
 		//TODO: Better algorithm?
@@ -38,6 +38,13 @@ public class GraphAnalyzer {
 		return false;
 	}
 
+	/**
+	 * Checks whether two edges connect the same pair of nodes
+	 * This function is symmetric
+	 * @param e1 An arbitrary CyEdge
+	 * @param e2 An arbitrary CyEdge
+	 * @return true if the edges connect the same pair of nodes, false otherwise
+	 */
 	private static boolean connectSameNodes(CyEdge e1, CyEdge e2) {
 		if (//Treating all edges as undirected here
 				(e1.getSource() == e2.getTarget() && e1.getTarget() == e2.getSource()) ||
@@ -61,7 +68,7 @@ public class GraphAnalyzer {
 	 * Generates a fitting bitmask by choosing the reduction rules that appear to be the best choice based on current research
 	 * @param containsRealValues
 	 * @param heuristic
-	 * @return
+	 * @return The bitmask as a String
 	 */
 	public static String suggestReductionRules(boolean containsRealValues, boolean heuristic) {
 
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java
index 8125643..87fb8c9 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/taskFactories/YoshikoCommand.java
@@ -18,6 +18,9 @@ public enum YoshikoCommand {
 		if (this==PERFORM_ALGORITHM) {
 			return "cluster"; //TODO: Dynamic
 		}
+		else if (this==CREATE_CLUSTER_VIEW) {
+			return "createcvs";
+		}
 		return "null";
 	}
 }
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
index 0535700..8920a78 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
@@ -76,7 +76,7 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask {
 	public ParameterSet parameterSet = null;
 
 	@Tunable(description="Network to analyze for clusters", context="nogui")
-	public CyNetwork net;
+	public CyNetwork net = CyCore.cy.getCurrentNetwork();
 
 	//Temps, pointing to and need to be freed in C++
 	private LibraryInput c_input;
@@ -289,7 +289,7 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask {
 
 	@Override
 	public <R> R getResults(Class<? extends R> type) {
-		//TODO:
+		//TODO: Return Result in some format that is suitable for console applications
 		if (type.equals(YoshikoResult.class)) {
 			return (R) (result!=null ? result : null);
 		}
-- 
GitLab