diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index abdea9ac032d4655898933f93050f48bf9581d14..839d647eef851c560a9854ff81d9caa1df594ced 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 encoding/<project>=UTF-8 diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java index 63e208af500eddd9c62d90a8dd1d64f18821276c..d9eb0bb43fe679776a1dc773319d45cfa4d75027 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java @@ -59,6 +59,8 @@ public class YoshikoCluster { private ArrayList<CyNode> nodes; private CySubNetwork net; + private Image img; + //SYMBOLIC LINKS private final CyNetwork originalGraph; private Logger logger = YoshikoLogger.getInstance().getLogger(); @@ -70,28 +72,26 @@ public class YoshikoCluster { this.nodes = new ArrayList<CyNode>(); } - private void createSubNetwork() { + public void createSubNetwork() { - if (net == null) { - CyRootNetwork originalGraphAsRoot = CyCore.rootNetworkManager.getRootNetwork(originalGraph); - - //Create nested graph and cluster subnet - ArrayList<CyEdge> inducedEdges = new ArrayList<CyEdge>(); - for (CyNode n: nodes) { - //Sadly Cytoscape doesnt provide a comfort function here - List<CyEdge> adjacentEdges = originalGraph.getAdjacentEdgeList(n, CyEdge.Type.ANY); - for (CyEdge e: adjacentEdges) { - if (nodes.contains(e.getSource()) && nodes.contains(e.getTarget())) { - inducedEdges.add(e); - } + CyRootNetwork originalGraphAsRoot = CyCore.rootNetworkManager.getRootNetwork(originalGraph); + + //Create nested graph and cluster subnet + ArrayList<CyEdge> inducedEdges = new ArrayList<CyEdge>(); + for (CyNode n: nodes) { + //Sadly Cytoscape doesnt provide a comfort function here + List<CyEdge> adjacentEdges = originalGraph.getAdjacentEdgeList(n, CyEdge.Type.ANY); + for (CyEdge e: adjacentEdges) { + if (nodes.contains(e.getSource()) && nodes.contains(e.getTarget())) { + inducedEdges.add(e); } } - CySubNetwork subnet = originalGraphAsRoot.addSubNetwork(nodes ,inducedEdges); + } + CySubNetwork subnet = originalGraphAsRoot.addSubNetwork(nodes ,inducedEdges); - subnet.getRow(subnet).set(CyNetwork.NAME, LocalizationManager.get("cluster")+" "+(id+1)); + subnet.getRow(subnet).set(CyNetwork.NAME, LocalizationManager.get("cluster")+" "+(id+1)); - net = subnet; //Save for further reference - } + net = subnet; //Save for further reference } /** @@ -114,12 +114,20 @@ public class YoshikoCluster { } - public void generateImage(JLabel label, int width, int height) { + public void applyImage(JLabel label, int width, int height) { if (net == null) { - createSubNetwork(); + return; + } + + if (img != null) { + getImage(width,height,label); + label.setIcon(new ImageIcon(img)); + return; } + } + private void getImage(int width, int height,JLabel label) { final CyNetworkView view = CyCore.networkViewFactory.createNetworkView(net); //layout cluster @@ -150,7 +158,7 @@ public class YoshikoCluster { @Override public void run() { - Image img = renderingEngine.createImage(width,height); + img = renderingEngine.createImage(width,height); label.setIcon(new ImageIcon(img)); renderingEngine.dispose(); @@ -161,11 +169,8 @@ public class YoshikoCluster { } - @Override - public void cancel() { - //Nothing to do as GC is handled by JAVA - } + public void cancel() {} } ); @@ -173,8 +178,6 @@ public class YoshikoCluster { CyCore.dialogTaskManager.execute( createLayout ); - - } public int getSize() { @@ -186,9 +189,6 @@ public class YoshikoCluster { } public CySubNetwork getSubNetwork() { - if (net == null) { - createSubNetwork(); - } return net; } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java index bd705af8c5f56118a560ff77295127622dcaea19..f351f01c9191cf03ad899f59aa5c6819a2bc697d 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java @@ -46,130 +46,33 @@ public class YoshikoSolution { * The original Graph from which the solution was generated. * NOTE: This can be destroyed or modified during runtime while the solution still exists and may become invalid */ - private CyNetwork originalGraph; + private final CyNetwork originalGraph; public ArrayList<YoshikoCluster> cluster; - public int id; - public YoshikoSolution(CyNetwork originalGraph) { + private final long id; + + public YoshikoSolution(CyNetwork originalGraph, long id) { cluster = new ArrayList<YoshikoCluster>(); this.originalGraph = originalGraph; + this.id = id; } - /** - * Transforms this solution in a meta-graph where each cluster is represented by one node - * The nodes are linked to subgraphs representing the cluster and also their size is scaled relative to cluster size - */ - public void exportMetaGraph() { - - CyNetwork metaGraph = CyCore.networkFactory.createNetwork(); - - metaGraph.getRow(metaGraph).set(CyNetwork.NAME, LocalizationManager.get("metaGraph")); - - metaGraph.getDefaultNodeTable().createColumn("clusterSize", Integer.class, false); - metaGraph.getDefaultEdgeTable().createColumn("edgeStrength", Integer.class, false); - - CyLayoutAlgorithm layout = CyCore.layoutAlgorithmManager.getDefaultLayout(); - - - //Map Cluster to Nodes for further reference - HashMap<YoshikoCluster,CyNode> map = new HashMap<YoshikoCluster,CyNode>(); - - - //Add nodes - for (YoshikoCluster c: cluster) { - - - - CyNode clusterNode = metaGraph.addNode(); - CySubNetwork subnet = c.getSubNetwork(); - CyCore.networkManager.addNetwork(subnet); - //Create network view and register it - CyNetworkView subnetView = CyCore.networkViewFactory.createNetworkView(subnet); - //layout cluster - CyCore.dialogTaskManager.execute( - layout.createTaskIterator( - subnetView, - layout.getDefaultLayoutContext(), - CyLayoutAlgorithm.ALL_NODE_VIEWS, - null - ) - ); - - StyleManager.style(subnetView,CyCore.visualMappingManager.getCurrentVisualStyle()); + //_____________GETTER / SETTER ________________// - CyCore.networkViewManager.addNetworkView(subnetView); - - clusterNode.setNetworkPointer(subnet); - //Set node attributes - metaGraph.getRow(clusterNode).set("name", LocalizationManager.get("cluster")+" "+c.getID()); - metaGraph.getRow(clusterNode).set(StyleManager.CLUSTERSIZE_COLUMN_NAME,c.getSize()); - map.put(c, clusterNode); - } - - //Add edges (O(|C|^2*|V|^2) can maybe be improved? //TODO - for (YoshikoCluster c1:cluster) { - for (YoshikoCluster c2:cluster) { - if ( - metaGraph.containsEdge(map.get(c1),map.get(c2)) - || c1 == c2 - ) { - continue; - } - for (CyNode c1n : c1.getSubNetwork().getNodeList()) { - for (CyNode c2n : c2.getSubNetwork().getNodeList()) { - if (originalGraph.containsEdge(c1n, c2n) || originalGraph.containsEdge(c2n, c1n)) { - if (!metaGraph.containsEdge(map.get(c1), map.get(c2))){ - CyEdge edge = metaGraph.addEdge(map.get(c1), map.get(c2), false); - metaGraph.getRow(edge).set(StyleManager.EDGESTRENGTH_COLUMN_NAME,1); - } - else { - CyEdge edge = metaGraph.getConnectingEdgeList(map.get(c1), map.get(c2), Type.ANY).get(0); - metaGraph.getRow(edge).set(StyleManager.EDGESTRENGTH_COLUMN_NAME, - metaGraph.getRow(edge).get(StyleManager.EDGESTRENGTH_COLUMN_NAME, Integer.class)+1 - ); - } - } - } - } - } - } - - CyNetworkView view = CyCore.networkViewFactory.createNetworkView(metaGraph); - - //Layout and style solution - - TaskIterator it = layout.createTaskIterator( - view, - layout.getDefaultLayoutContext(), - CyLayoutAlgorithm.ALL_NODE_VIEWS, - null - ); - - it.append(new Task() { - - @Override - public void run(TaskMonitor taskMonitor) throws Exception { - StyleManager.styleWithMapping(view, CyCore.visualMappingManager.getCurrentVisualStyle()); - } - - @Override - public void cancel() {} - - }); - - CyCore.dialogTaskManager.execute( - it - ); - - CyCore.networkManager.addNetwork(metaGraph); - CyCore.networkViewManager.addNetworkView( - view - ); + public ArrayList<YoshikoCluster> getCluster() { + return cluster; + } - view.updateView(); + public CyNetwork getOriginalGraph() { + return originalGraph; + } - CyCore.cy.setCurrentNetworkView(view); + /** + * @return the id + */ + public long getId() { + return id; } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java index 78ec25c416f1b960ed779cd5a9d7846df582dc31..79a1fbf3bbdd8c7e76210ba0ab4db6c0a1526293 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java @@ -1,16 +1,16 @@ /******************************************************************************* * Copyright (C) 2017 Philipp Spohr - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -42,40 +42,41 @@ import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; @SuppressWarnings("serial") public class ClusterView extends JPanel { - + private final JLabel title; private final JLabel clusterSize; private final JLabel icon; private final BasicCollapsiblePanel nodeList; - - private final Border regularBorder = BorderFactory.createLineBorder(Color.GRAY,3); + + private final Border regularBorder = BorderFactory.createLineBorder(Color.GRAY,1); private final Border highlightBorder = BorderFactory.createLineBorder(GraphicsLoader.yoshikoGreen,3); - + private final Border selectedBorder = BorderFactory.createLineBorder(Color.BLUE,3); + //SYMBOLIC LINKS - + /**Simple array list containing references to the nodes that are represented by this cluster view - * + * */ private YoshikoCluster cluster; - + public ClusterView(YoshikoCluster c) { - - this.cluster = c; - + + this.cluster = c; + //Swing init this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); - + title = new JLabel(LocalizationManager.get("cluster")+" "+(c.getID()+1)); clusterSize = new JLabel(LocalizationManager.get("clusterSize")+" "+c.getSize()); icon = new JLabel(); icon.setBorder(BorderFactory.createLineBorder(Color.BLACK)); - cluster.generateImage(icon,128, 128); + cluster.applyImage(icon,128, 128); SwingUtil.addAll(this,title,clusterSize,icon); this.add(Box.createVerticalStrut(4)); - + nodeList = new BasicCollapsiblePanel(LocalizationManager.get("nodes")); - + //Loop over nodes in the cluster and add them to the view for (CyNode n : c.getSubNetwork().getNodeList()) { nodeList.add( @@ -84,15 +85,15 @@ public class ClusterView extends JPanel { ) ); } - + this.add(nodeList); - + this.addMouseListener(mouseListener); - + this.setBorder(regularBorder); } - + private MouseListener mouseListener = new MouseListener() { @Override @@ -102,7 +103,7 @@ public class ClusterView extends JPanel { public void mousePressed(MouseEvent e) { cluster.select(); } - + @Override public void mouseReleased(MouseEvent e) {} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java index 59a51fdc2ff343bdd65e6b8f9daf69ffef88d3a1..dfb5ab9f753325ec12520f00b86b17e6a01bebc3 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java @@ -53,7 +53,6 @@ import org.cytoscape.util.swing.BasicCollapsiblePanel; import org.cytoscape.work.AbstractTask; import org.cytoscape.work.TaskIterator; -import de.hhu.ba.yoshikoWrapper.core.AlgorithmTask; import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.ParameterSet; @@ -63,6 +62,7 @@ import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader; import de.hhu.ba.yoshikoWrapper.swing.LanguageSwitcherPanelFactory; import de.hhu.ba.yoshikoWrapper.swing.LibraryPanelFactory; import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; +import de.hhu.ba.yoshikoWrapper.tasks.AlgorithmTask; /**This class describes the Swing Panel that the user interacts with in cytoscape * diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java index 689695db6d437282216734c7ad08d6b4944d93bb..d541c1aa21cbe80473fd9acf39f626d2c7be9efe 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java @@ -162,7 +162,7 @@ public class ResultPanel extends JPanel implements CytoPanelComponent{ private void addSolutionTab(YoshikoSolution s) { SolutionTab tab = new SolutionTab(s); solutionTabs.add( - LocalizationManager.get("solution")+" "+(s.id+1), + LocalizationManager.get("solution")+" "+(s.getId()+1), tab ); } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java index a017efc83b95a601a4aa6218345b89df6aa3d2ef..2f593cdceb8081c1b0936b67bafa8f1960cf523f 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java @@ -32,10 +32,14 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import org.cytoscape.work.TaskIterator; + +import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster; import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution; import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; +import de.hhu.ba.yoshikoWrapper.tasks.CreateMetaGraphTask; @SuppressWarnings("serial") public class SolutionTab extends JPanel { @@ -88,7 +92,11 @@ public class SolutionTab extends JPanel { @Override public void actionPerformed(ActionEvent e) { - solution.exportMetaGraph(); + CyCore.dialogTaskManager.execute( + new TaskIterator(1, + new CreateMetaGraphTask(solution) + ) + ); } }); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java similarity index 91% rename from src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java rename to src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java index faccd1cc19824fd080c206284c05eff798fc2b05..787ee1c02f623a679a4695b2a3a1bb5003880209 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ -package de.hhu.ba.yoshikoWrapper.core; +package de.hhu.ba.yoshikoWrapper.tasks; import java.awt.Window; import java.util.Properties; @@ -34,6 +34,11 @@ import org.cytoscape.work.AbstractTask; import org.cytoscape.work.TaskMonitor; import org.slf4j.Logger; +import de.hhu.ba.yoshikoWrapper.core.CyCore; +import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; +import de.hhu.ba.yoshikoWrapper.core.NetworkParser; +import de.hhu.ba.yoshikoWrapper.core.ParameterSet; +import de.hhu.ba.yoshikoWrapper.core.StatusInformer; import de.hhu.ba.yoshikoWrapper.cytoUtil.NodeMap; import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster; import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoResult; @@ -49,6 +54,7 @@ import de.hhu.ba.yoshikoWrapper.swing.components.ResultPanel; public class AlgorithmTask extends AbstractTask { + private String SOLUTION_COLUMN_PREFIX = "yoshikoSolution_"; //Symbolic links private static Logger logger = YoshikoLogger.getInstance().getLogger(); @@ -137,20 +143,18 @@ public class AlgorithmTask extends AbstractTask { long numberOfSolutions = result.getNumberOfSolutions(); - taskMonitor.setStatusMessage("Found: "+numberOfSolutions+" solutions!"); //TODO localize YoshikoResult yoshikoResult = new YoshikoResult(); yoshikoResult.flags = result.getFlags(); - System.out.print("ILP FLAG: "+yoshikoResult.flags.getIlpGenerated()); //Loop over (multiple) solutions for (long i=0;i<numberOfSolutions;i++) { taskMonitor.setStatusMessage("Processing solution "+(i+1)+" of "+numberOfSolutions); - YoshikoSolution solution = new YoshikoSolution(net); - String columnName = "YOSHIKO_SOLUTION_"+(i+1); + YoshikoSolution solution = new YoshikoSolution(net,i); + String columnName = SOLUTION_COLUMN_PREFIX+(i+1); net.getDefaultNodeTable().deleteColumn(columnName); net.getDefaultNodeTable().createColumn(columnName, String.class, false); @@ -170,16 +174,18 @@ public class AlgorithmTask extends AbstractTask { long sizeOfCluster = clusterVector.size(); for (int l=0;l<sizeOfCluster;l++) { //Unsafe mismatch int long - taskMonitor.setStatusMessage("Processing entry "+(l+1)+ " of "+sizeOfCluster); + taskMonitor.setStatusMessage("Processing node "+(l+1)+ " of "+sizeOfCluster); int nodeID = clusterVector.get(l); CyNode node = nodeMap.indexOf(nodeID); //<<< Another int/long conversion cluster.addNode(node); net.getRow(node).set(columnName, ""+(k+1)); //Add Cluster ID in table (Remove in final version?) } - cluster.getSubNetwork(); + cluster.createSubNetwork(); + //Register cluster with solution for further reference solution.cluster.add(cluster); } + //Register solution with result for further reference yoshikoResult.solutions.add(solution); } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java new file mode 100644 index 0000000000000000000000000000000000000000..6f75831a8157f92f61ea52be8aa7e9739c7aa7db --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java @@ -0,0 +1,143 @@ +package de.hhu.ba.yoshikoWrapper.tasks; + +import java.util.HashMap; + +import org.cytoscape.model.CyEdge; +import org.cytoscape.model.CyNetwork; +import org.cytoscape.model.CyNode; +import org.cytoscape.model.CyEdge.Type; +import org.cytoscape.model.subnetwork.CySubNetwork; +import org.cytoscape.view.layout.CyLayoutAlgorithm; +import org.cytoscape.view.model.CyNetworkView; +import org.cytoscape.work.AbstractTask; +import org.cytoscape.work.Task; +import org.cytoscape.work.TaskIterator; +import org.cytoscape.work.TaskMonitor; + +import de.hhu.ba.yoshikoWrapper.core.CyCore; +import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; +import de.hhu.ba.yoshikoWrapper.cytoUtil.StyleManager; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution; + +public class CreateMetaGraphTask extends AbstractTask { + + private final YoshikoSolution solution; + + public CreateMetaGraphTask(YoshikoSolution s) { + this.solution = s; + } + + @Override + public void run(TaskMonitor taskMonitor) throws Exception { + CyNetwork metaGraph = CyCore.networkFactory.createNetwork(); + + metaGraph.getRow(metaGraph).set(CyNetwork.NAME, LocalizationManager.get("metaGraph")); + + metaGraph.getDefaultNodeTable().createColumn("clusterSize", Integer.class, false); + metaGraph.getDefaultEdgeTable().createColumn("edgeStrength", Integer.class, false); + + CyLayoutAlgorithm layout = CyCore.layoutAlgorithmManager.getDefaultLayout(); + + + //Map Cluster to Nodes for further reference + HashMap<YoshikoCluster,CyNode> map = new HashMap<YoshikoCluster,CyNode>(); + + + //Add nodes + for (YoshikoCluster c: solution.getCluster()) { + + + + CyNode clusterNode = metaGraph.addNode(); + CySubNetwork subnet = c.getSubNetwork(); + CyCore.networkManager.addNetwork(subnet); + //Create network view and register it + CyNetworkView subnetView = CyCore.networkViewFactory.createNetworkView(subnet); + //layout cluster + CyCore.dialogTaskManager.execute( + layout.createTaskIterator( + subnetView, + layout.getDefaultLayoutContext(), + CyLayoutAlgorithm.ALL_NODE_VIEWS, + null + ) + ); + + StyleManager.style(subnetView,CyCore.visualMappingManager.getCurrentVisualStyle()); + + CyCore.networkViewManager.addNetworkView(subnetView); + + clusterNode.setNetworkPointer(subnet); + //Set node attributes + metaGraph.getRow(clusterNode).set("name", LocalizationManager.get("cluster")+" "+c.getID()); + metaGraph.getRow(clusterNode).set(StyleManager.CLUSTERSIZE_COLUMN_NAME,c.getSize()); + map.put(c, clusterNode); + } + + //Add edges (O(|C|^2*|V|^2) can maybe be improved? //TODO + for (YoshikoCluster c1:solution.getCluster()) { + for (YoshikoCluster c2:solution.getCluster()) { + if ( + metaGraph.containsEdge(map.get(c1),map.get(c2)) + || c1 == c2 + ) { + continue; + } + for (CyNode c1n : c1.getSubNetwork().getNodeList()) { + for (CyNode c2n : c2.getSubNetwork().getNodeList()) { + if (solution.getOriginalGraph().containsEdge(c1n, c2n) || solution.getOriginalGraph().containsEdge(c2n, c1n)) { + if (!metaGraph.containsEdge(map.get(c1), map.get(c2))){ + CyEdge edge = metaGraph.addEdge(map.get(c1), map.get(c2), false); + metaGraph.getRow(edge).set(StyleManager.EDGESTRENGTH_COLUMN_NAME,1); + } + else { + CyEdge edge = metaGraph.getConnectingEdgeList(map.get(c1), map.get(c2), Type.ANY).get(0); + metaGraph.getRow(edge).set(StyleManager.EDGESTRENGTH_COLUMN_NAME, + metaGraph.getRow(edge).get(StyleManager.EDGESTRENGTH_COLUMN_NAME, Integer.class)+1 + ); + } + } + } + } + } + } + + CyNetworkView view = CyCore.networkViewFactory.createNetworkView(metaGraph); + + //Layout and style solution + + TaskIterator it = layout.createTaskIterator( + view, + layout.getDefaultLayoutContext(), + CyLayoutAlgorithm.ALL_NODE_VIEWS, + null + ); + + it.append(new Task() { + + @Override + public void run(TaskMonitor taskMonitor) throws Exception { + StyleManager.styleWithMapping(view, CyCore.visualMappingManager.getCurrentVisualStyle()); + } + + @Override + public void cancel() {} + + }); + + CyCore.dialogTaskManager.execute( + it + ); + + CyCore.networkManager.addNetwork(metaGraph); + CyCore.networkViewManager.addNetworkView( + view + ); + + view.updateView(); + + CyCore.cy.setCurrentNetworkView(view); + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/package-info.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..dd84947abcf1a87b991a1337d4374131145ebb61 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Philipp Spohr, Sep 14, 2017 + * + */ +package de.hhu.ba.yoshikoWrapper.tasks; \ No newline at end of file