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

Some more work on the GUI

parent fc7972eb
No related branches found
No related tags found
No related merge requests found
Showing with 120 additions and 34 deletions
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version> <version>3.0</version>
<configuration> <configuration>
<source>1.6</source> <source>1.8</source>
<target>1.6</target> <target>1.8</target>
<optimize>true</optimize> <optimize>true</optimize>
<showWarnings>true</showWarnings> <showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
......
...@@ -2,9 +2,12 @@ package de.hhu.ba.yoshikoWrapper.core; ...@@ -2,9 +2,12 @@ package de.hhu.ba.yoshikoWrapper.core;
//TODO: ADD LOGGER SYSTEM //TODO: ADD LOGGER SYSTEM
import org.cytoscape.application.CyApplicationManager; import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode; import org.cytoscape.model.CyNode;
import org.slf4j.Logger;
import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_std__vectorT_int_t; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_std__vectorT_int_t;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput;
...@@ -12,22 +15,47 @@ import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_ysk__ClusterEditingSolutions; ...@@ -12,22 +15,47 @@ import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_ysk__ClusterEditingSolutions;
public class Core { public class Core {
private static CyApplicationManager cy;
//Symbolic links
private static CyApplicationManager cy;
private static Logger logger = YoshikoLogger.getInstance().getLogger();
public static void performYoshiko(int timeLimit) { public static void performYoshiko(
int timeLimit,
CyColumn weightColumn,
double insertionCostDefault,
double deletionCostDefault
)
{
//Get current network
CyNetwork currentNetwork = cy.getCurrentNetwork(); CyNetwork currentNetwork = cy.getCurrentNetwork();
if (currentNetwork == null) { if (currentNetwork == null) {
//TODO logger.warn("There is no network loaded. You need to load a network first!");
return; return;
} }
//Set time limit
LibraryInterface.setTimeLimit(timeLimit); LibraryInterface.setTimeLimit(timeLimit);
//Create a node map to identify nodes and eges in the solution
NodeMap nodeMap = new NodeMap(currentNetwork); NodeMap nodeMap = new NodeMap(currentNetwork);
SWIGTYPE_p_yskInput__LibraryInput input = NetworkParser.parseNetwork(currentNetwork,nodeMap); //Generate an input instance from the network
SWIGTYPE_p_yskInput__LibraryInput input = NetworkParser.parseNetwork(
currentNetwork,
nodeMap,
weightColumn,
deletionCostDefault
);
//Set the default value for insertion cost
LibraryInterface.LibraryInput_setDefaultInsertionCost(input, insertionCostDefault);
//Call Yoshiko <<< Algorithm is performed here
SWIGTYPE_p_ysk__ClusterEditingSolutions solutions = LibraryInterface.processLibraryInput(input); SWIGTYPE_p_ysk__ClusterEditingSolutions solutions = LibraryInterface.processLibraryInput(input);
long numberOfSolutions = LibraryInterface.ClusterEditingSolutions_getNumberOfSolutions(solutions); long numberOfSolutions = LibraryInterface.ClusterEditingSolutions_getNumberOfSolutions(solutions);
System.out.println("Found: "+numberOfSolutions+" solutions!"); System.out.println("Found: "+numberOfSolutions+" solutions!");
double modificationCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(solutions); double modificationCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(solutions);
......
...@@ -2,35 +2,54 @@ package de.hhu.ba.yoshikoWrapper.core; ...@@ -2,35 +2,54 @@ package de.hhu.ba.yoshikoWrapper.core;
import java.util.List; import java.util.List;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyEdge; import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyRow; import org.cytoscape.model.CyRow;
import org.slf4j.Logger;
import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput;
public class NetworkParser { public class NetworkParser {
//**TODO MAKE DYNAMIC //Symbolic Links
private static String weightIndex = "Weight"; private static Logger logger = YoshikoLogger.getInstance().getLogger();
public static SWIGTYPE_p_yskInput__LibraryInput parseNetwork(
CyNetwork net,
NodeMap nodeMap,
public static SWIGTYPE_p_yskInput__LibraryInput parseNetwork(CyNetwork net,NodeMap nodeMap) { CyColumn weightColumn,
double deletionCostDefault
)
{
//Create an empty instance / fetch C++ object pointer
SWIGTYPE_p_yskInput__LibraryInput generatedInput = LibraryInterface.new_LibraryInput(); SWIGTYPE_p_yskInput__LibraryInput generatedInput = LibraryInterface.new_LibraryInput();
if (net != null){ if (net != null){
//Create an empty full graph with a given size
LibraryInterface.LibraryInput_setSize(generatedInput, net.getNodeCount()); LibraryInterface.LibraryInput_setSize(generatedInput, net.getNodeCount());
//Fetch edges
List<CyEdge> edges = net.getEdgeList(); List<CyEdge> edges = net.getEdgeList();
Class<?> weightType = net.getDefaultEdgeTable().getColumn(weightIndex).getType();
System.out.println("Column has type:"+weightType.getName()); //Find out if the weights are double or int
@SuppressWarnings("unchecked")
Class<? extends Number> weightType = (Class<? extends Number>) weightColumn.getType();
logger.info("Column has type: "+weightType.getName());
//Loop over edges
for (CyEdge e : edges) { for (CyEdge e : edges) {
CyRow edgeEntry = net.getRow(e); CyRow edgeEntry = net.getRow(e);
double weight = 0.0; double weight = deletionCostDefault;
if (weightType == Integer.class) { try {
weight = (double)edgeEntry.get(weightIndex, Integer.class); weight = (double)edgeEntry.get(weightColumn.getName(), weightType);
} }
System.out.println("Found Edge: "+edgeEntry.get("name", String.class)+ "with weight:"+weight); catch(Exception ex) {
//Invalid entry (no entry)
logger.info("No valid edit costs defined for: "+edgeEntry.get("name", String.class)+", falling back to default value!");
}
logger.debug("Found Edge: "+edgeEntry.get("name", String.class)+ "with weight:"+weight);
LibraryInterface.LibraryInput_addEdge(generatedInput, LibraryInterface.LibraryInput_addEdge(generatedInput,
nodeMap.get(e.getSource()), nodeMap.get(e.getSource()),
......
...@@ -13,7 +13,7 @@ public class DoubleInputField extends JFormattedTextField{ ...@@ -13,7 +13,7 @@ public class DoubleInputField extends JFormattedTextField{
this.setColumns(8); this.setColumns(8);
} }
public int getTimeLimit() { public double getValueAsDouble() {
return Integer.parseInt(getText()); return Double.parseDouble(getText());
} }
} }
package de.hhu.ba.yoshikoWrapper.gui; package de.hhu.ba.yoshikoWrapper.gui;
import javax.swing.BorderFactory;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.border.EtchedBorder;
import org.cytoscape.model.CyColumn;
@SuppressWarnings("serial") //Will never be serialized @SuppressWarnings("serial") //Will never be serialized
public class EditCostPanel extends ComfortPanel { public class EditCostPanel extends ComfortPanel {
...@@ -13,14 +17,35 @@ public class EditCostPanel extends ComfortPanel { ...@@ -13,14 +17,35 @@ public class EditCostPanel extends ComfortPanel {
private JLabel dcLabel; private JLabel dcLabel;
public EditCostPanel() { public EditCostPanel() {
//Initialize components
modCostMapper = new ModificationCostMapper(); modCostMapper = new ModificationCostMapper();
icField = new DoubleInputField(0,Double.NEGATIVE_INFINITY); icField = new DoubleInputField(Double.NEGATIVE_INFINITY,0);
dcField = new DoubleInputField(0,Double.POSITIVE_INFINITY); dcField = new DoubleInputField(0,Double.POSITIVE_INFINITY);
icField.setText("-1.0");
dcField.setText("1.0");
icLabel = new JLabel("Insertion Cost:"); icLabel = new JLabel("Insertion Cost:");
dcLabel = new JLabel("Deletion Cost:"); dcLabel = new JLabel("Deletion Cost:");
icLabel.setLabelFor(icField); icLabel.setLabelFor(icField);
dcLabel.setLabelFor(dcField); dcLabel.setLabelFor(dcField);
this.addAll(modCostMapper,icField,dcField,icLabel,dcLabel); this.addAll(modCostMapper,icField,dcField,icLabel,dcLabel);
//
this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
}
//SETTER / GETTER
public CyColumn getWeightColumn() {
return modCostMapper.getValue();
}
public double getDefaultInsertionCost() {
return icField.getValueAsDouble();
}
public double getDefaultDeletionCost() {
return dcField.getValueAsDouble();
} }
} }
...@@ -21,7 +21,7 @@ public class FormatHelper { ...@@ -21,7 +21,7 @@ public class FormatHelper {
public static NumberFormatter getDoubleFormatter(double minValue, double maxValue) { public static NumberFormatter getDoubleFormatter(double minValue, double maxValue) {
NumberFormat format = NumberFormat.getInstance(); NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format); NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class); formatter.setValueClass(Double.class);
formatter.setMinimum(minValue); formatter.setMinimum(minValue);
formatter.setMaximum(maxValue); formatter.setMaximum(maxValue);
formatter.setAllowsInvalid(false); formatter.setAllowsInvalid(false);
......
...@@ -97,7 +97,12 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { ...@@ -97,7 +97,12 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (YoshikoLoader.isLibraryLoaded()){ if (YoshikoLoader.isLibraryLoaded()){
Core.performYoshiko(timeLimitSetter.getTimeLimit()); Core.performYoshiko(
timeLimitSetter.getTimeLimit(),
ecPanel.getWeightColumn(),
ecPanel.getDefaultInsertionCost(),
ecPanel.getDefaultDeletionCost()
);
} }
} }
......
...@@ -10,6 +10,8 @@ import javax.swing.JComboBox; ...@@ -10,6 +10,8 @@ import javax.swing.JComboBox;
import org.cytoscape.application.CyApplicationManager; import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyColumn; import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.events.ColumnCreatedEvent;
import org.cytoscape.model.events.ColumnDeletedListener;
import de.hhu.ba.yoshikoWrapper.core.Core; import de.hhu.ba.yoshikoWrapper.core.Core;
...@@ -36,7 +38,6 @@ public class ModificationCostMapper extends ComfortPanel { ...@@ -36,7 +38,6 @@ public class ModificationCostMapper extends ComfortPanel {
//Initial call to get table values //Initial call to get table values
updateValues(); updateValues();
//Add a focus listener to update values //Add a focus listener to update values
//TODO: This might be a bit inelegant but there is no way to get a callback from CS when a table changes values
tableFields.addFocusListener (new FocusListener() { tableFields.addFocusListener (new FocusListener() {
@Override @Override
...@@ -57,10 +58,13 @@ public class ModificationCostMapper extends ComfortPanel { ...@@ -57,10 +58,13 @@ public class ModificationCostMapper extends ComfortPanel {
CyNetwork net = cy.getCurrentNetwork(); CyNetwork net = cy.getCurrentNetwork();
if (net != null) { //Check if a network is loaded if (net != null) { //Check if a network is loaded
for (CyColumn c : net.getDefaultEdgeTable().getColumns()){ for (CyColumn c : net.getDefaultEdgeTable().getColumns()){
//Only add columns with numeric values
if (c.getType() == Integer.class || c.getType() == Double.class) {
tableFields.addItem(c); tableFields.addItem(c);
} }
} }
} }
}
public CyColumn getValue() { public CyColumn getValue() {
if (useMapping.isSelected()) { if (useMapping.isSelected()) {
......
...@@ -93,10 +93,6 @@ public class LibraryInterface { ...@@ -93,10 +93,6 @@ public class LibraryInterface {
LibraryInterfaceJNI.delete_LibraryInput(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self)); LibraryInterfaceJNI.delete_LibraryInput(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self));
} }
public static void LibraryInput_setSize(SWIGTYPE_p_yskInput__LibraryInput self, long id) {
LibraryInterfaceJNI.LibraryInput_setSize(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), id);
}
public static void LibraryInput_addEdge(SWIGTYPE_p_yskInput__LibraryInput self, long sourceID, long targetID, double cost) { public static void LibraryInput_addEdge(SWIGTYPE_p_yskInput__LibraryInput self, long sourceID, long targetID, double cost) {
LibraryInterfaceJNI.LibraryInput_addEdge__SWIG_0(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), sourceID, targetID, cost); LibraryInterfaceJNI.LibraryInput_addEdge__SWIG_0(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), sourceID, targetID, cost);
} }
...@@ -105,6 +101,14 @@ public class LibraryInterface { ...@@ -105,6 +101,14 @@ public class LibraryInterface {
LibraryInterfaceJNI.LibraryInput_addEdge__SWIG_1(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), sourceID, targetID, cost, permanent, forbidden); LibraryInterfaceJNI.LibraryInput_addEdge__SWIG_1(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), sourceID, targetID, cost, permanent, forbidden);
} }
public static void LibraryInput_setSize(SWIGTYPE_p_yskInput__LibraryInput self, long id) {
LibraryInterfaceJNI.LibraryInput_setSize(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), id);
}
public static void LibraryInput_setDefaultInsertionCost(SWIGTYPE_p_yskInput__LibraryInput self, double cost) {
LibraryInterfaceJNI.LibraryInput_setDefaultInsertionCost(SWIGTYPE_p_yskInput__LibraryInput.getCPtr(self), cost);
}
public static String getVersionString() { public static String getVersionString() {
return LibraryInterfaceJNI.getVersionString(); return LibraryInterfaceJNI.getVersionString();
} }
......
...@@ -29,9 +29,10 @@ public class LibraryInterfaceJNI { ...@@ -29,9 +29,10 @@ public class LibraryInterfaceJNI {
public final static native void delete_ClusterEditingSolutions(long jarg1); public final static native void delete_ClusterEditingSolutions(long jarg1);
public final static native long new_LibraryInput(); public final static native long new_LibraryInput();
public final static native void delete_LibraryInput(long jarg1); public final static native void delete_LibraryInput(long jarg1);
public final static native void LibraryInput_setSize(long jarg1, long jarg2);
public final static native void LibraryInput_addEdge__SWIG_0(long jarg1, long jarg2, long jarg3, double jarg4); public final static native void LibraryInput_addEdge__SWIG_0(long jarg1, long jarg2, long jarg3, double jarg4);
public final static native void LibraryInput_addEdge__SWIG_1(long jarg1, long jarg2, long jarg3, double jarg4, boolean jarg5, boolean jarg6); public final static native void LibraryInput_addEdge__SWIG_1(long jarg1, long jarg2, long jarg3, double jarg4, boolean jarg5, boolean jarg6);
public final static native void LibraryInput_setSize(long jarg1, long jarg2);
public final static native void LibraryInput_setDefaultInsertionCost(long jarg1, double jarg2);
public final static native String getVersionString(); public final static native String getVersionString();
public final static native long processLibraryInput(long jarg1); public final static native long processLibraryInput(long jarg1);
public final static native void setTimeLimit(int jarg1); public final static native void setTimeLimit(int jarg1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment