protected CyEdge getEdgeByName(CyNetwork net, String name) {
    for (CyEdge e : net.getEdgeList()) {
      if (name.equals(net.getRow(e).get(NAME, String.class))) return e;
    }

    return null;
  }
Exemplo n.º 2
0
  private void initVariables() {
    edgeAttributes = context.getSelectedEdgeAttributes();

    graph = new DirectedSparseMultigraph<>();
    idToNode = new HashMap<>();
    nodeList = network.getNodeList();
    edgeList = network.getEdgeList();
    nodeTable = network.getDefaultNodeTable();
    edgeTable = network.getDefaultEdgeTable();
  }
  public BellmanFordStatsImpl findPath(
      CyNetwork network, CyNode source, boolean directed, WeightFunction function) {

    Map<CyNode, MetaNode> nodeToMetaNodeMap = new IdentityHashMap<CyNode, MetaNode>();

    boolean negativeCycle = true;

    for (CyNode node : network.getNodeList()) {

      MetaNode metaNode = new MetaNode(node, Double.POSITIVE_INFINITY, null);
      nodeToMetaNodeMap.put(node, metaNode);
    }

    nodeToMetaNodeMap.get(source).setDistance(0.0);

    for (int i = 0; i < network.getNodeCount() - 1; i++) {

      for (CyEdge edge : network.getEdgeList()) {

        MetaNode sourceMetaNode = nodeToMetaNodeMap.get(edge.getSource());
        MetaNode targetMetaNode = nodeToMetaNodeMap.get(edge.getTarget());

        if (targetMetaNode.getDistance()
            > sourceMetaNode.getDistance() + function.getWeight(edge)) {
          targetMetaNode.setDistance(sourceMetaNode.getDistance() + function.getWeight(edge));
          targetMetaNode.setPredecessor(sourceMetaNode.getNode());
        }
      }
    }

    for (CyEdge edge : network.getEdgeList()) {

      MetaNode sourceMetaNode = nodeToMetaNodeMap.get(edge.getSource());
      MetaNode targetMetaNode = nodeToMetaNodeMap.get(edge.getTarget());
      if (targetMetaNode.getDistance() > sourceMetaNode.getDistance() + function.getWeight(edge))
        negativeCycle = false;
    }

    return new BellmanFordStatsImpl(source, nodeToMetaNodeMap, negativeCycle);
  }
  @Override
  public void serialize(CyNetworkView networkView, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonProcessingException {
    jgen.useDefaultPrettyPrinter();

    jgen.writeStartObject();
    jgen.writeStringField(
        CytoscapeJsNetworkModule.FORMAT_VERSION_TAG, CytoscapeJsNetworkModule.FORMAT_VERSION);
    jgen.writeStringField(CytoscapeJsNetworkModule.GENERATED_BY_TAG, "cytoscape-" + version);
    jgen.writeStringField(
        CytoscapeJsNetworkModule.TARGET_CYJS_VERSION_TAG,
        CytoscapeJsNetworkModule.CYTOSCAPEJS_VERSION);

    final CyNetwork network = networkView.getModel();

    // Serialize network data table
    jgen.writeObjectFieldStart(DATA.getTag());
    jgen.writeObject(network.getRow(network));
    jgen.writeEndObject();

    jgen.writeObjectFieldStart(ELEMENTS.getTag());

    // Write array
    final List<CyNode> nodes = network.getNodeList();
    final List<CyEdge> edges = network.getEdgeList();

    jgen.writeArrayFieldStart(NODES.getTag());
    for (final CyNode node : nodes) {
      jgen.writeStartObject();

      // Data field
      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), node.getSUID().toString());
      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(node));
      jgen.writeEndObject();

      // Position and other visual props
      jgen.writeObject(networkView.getNodeView(node));

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(node).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeArrayFieldStart(EDGES.getTag());
    for (final CyEdge edge : edges) {
      jgen.writeStartObject();

      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), edge.getSUID().toString());
      jgen.writeStringField(SOURCE.getTag(), edge.getSource().getSUID().toString());
      jgen.writeStringField(TARGET.getTag(), edge.getTarget().getSUID().toString());

      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(edge));

      jgen.writeEndObject();

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(edge).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeEndObject();
  }
Exemplo n.º 5
0
 void cyLoad(CyNetwork gp) {
   net = gp;
   nodes = new ArrayList<CyNode>(net.getNodeList());
   edges = new ArrayList<CyEdge>(net.getEdgeList());
 }