Skip to content
Snippets Groups Projects
Commit 25315860 authored by Philipp Spohr's avatar Philipp Spohr
Browse files

Some refactor

parent de07bd9b
No related branches found
No related tags found
No related merge requests found
Showing
with 245 additions and 175 deletions
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
......@@ -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,9 +72,8 @@ 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
......@@ -92,7 +93,6 @@ public class YoshikoCluster {
net = subnet; //Save for further reference
}
}
/**
* Attempt to select the nodes belonging to this cluster in the original Graph given that they still exist
......@@ -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;
}
......
......@@ -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());
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);
}
//_____________GETTER / SETTER ________________//
//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;
public ArrayList<YoshikoCluster> getCluster() {
return cluster;
}
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());
public CyNetwork getOriginalGraph() {
return originalGraph;
}
@Override
public void cancel() {}
});
CyCore.dialogTaskManager.execute(
it
);
CyCore.networkManager.addNetwork(metaGraph);
CyCore.networkViewManager.addNetworkView(
view
);
view.updateView();
CyCore.cy.setCurrentNetworkView(view);
/**
* @return the id
*/
public long getId() {
return id;
}
}
......@@ -48,8 +48,9 @@ public class ClusterView extends JPanel {
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
......@@ -69,7 +70,7 @@ public class ClusterView extends JPanel {
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));
......
......@@ -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
*
......
......@@ -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
);
}
......
......@@ -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)
)
);
}
});
......
......@@ -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);
}
......
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);
}
}
/**
*
*/
/**
* @author Philipp Spohr, Sep 14, 2017
*
*/
package de.hhu.ba.yoshikoWrapper.tasks;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment