Esempio n. 1
0
  public static Matrix asMat(MLArray mlArray) {
    MLDouble mlArrayDbl = (MLDouble) mlArray;
    int rows = mlArray.getM();
    int cols = mlArray.getN();

    Matrix mat = SparseMatrixFactoryMTJ.INSTANCE.createMatrix(rows, cols);

    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < cols; c++) {
        mat.setElement(r, c, mlArrayDbl.get(r, c));
      }
    }
    return mat;
  }
Esempio n. 2
0
  private void decomposePassPaths(Map<Link, Set<Path>> routes, MLCell j) {
    Network network = optimContext.network;
    Map<Id<Node>, ? extends Node> nodenetwork = network.getNodes();
    ArrayList<MLArray> paths = j.cells();
    for (MLArray path : paths) {
      MLCell cellpath = (MLCell) path;
      if (path.getM() != 0) {
        List<Node> nodelist = new ArrayList<Node>();
        List<Link> linklist = new ArrayList<Link>();
        MLDouble route = (MLDouble) (cellpath.get(0));
        double[][] nodes = route.getArray();
        for (int i = 0; i < nodes.length - 1; i++) {
          int currnode = (int) nodes[i][0];
          int nextnode = (int) nodes[i + 1][0];
          Node start = nodenetwork.get(Id.createNodeId(Integer.toString(currnode)));
          Node finish = nodenetwork.get(Id.createNodeId(Integer.toString(nextnode)));
          nodelist.add(start);
          Collection<? extends Link> possiblelinks = start.getOutLinks().values();
          for (Link l : possiblelinks) {
            if (l.getToNode().equals(finish)) {
              linklist.add(l);
              break;
            }
          }
          if (i == nodes.length - 2) {
            nodelist.add(finish);
          }

          Path temppath = convertNodeListtoPath(nodelist, linklist);
          if (routes.get(linklist.get(0)) == null) { // add path to routelist
            routes.put(linklist.get(0), new HashSet<Path>());
          }
          routes.get(linklist.get(0)).add(temppath);
        }
      }
    }
  }