示例#1
0
  private void writeUndirectedMatrix(ValidateNETFile vmf, PrintWriter pw) {
    NETVertex nvi;
    NETVertex nvj;
    // float[][] matrix = new float[vmf.getVertices().size()][vmf.getVertices().size()];
    NETArcsnEdges nae;
    int source, target;
    float weight = (float) 0.0;
    // System.out.println(vmf.getEdges().size());
    pw.println(MATFileProperty.HEADER_MATRIX);
    for (int i = 0; i < vmf.getVertices().size(); i++) {
      nvi = (NETVertex) vmf.getVertices().get(i);
      for (int j = 0; j < vmf.getVertices().size(); j++) {
        nvj = (NETVertex) vmf.getVertices().get(j);
        for (int k = 0; k < vmf.getEdges().size(); k++) {
          nae = (NETArcsnEdges) vmf.getEdges().get(k);
          target = ((Integer) nae.getAttribute(NETFileProperty.ATTRIBUTE_TARGET)).intValue();
          source = ((Integer) nae.getAttribute(NETFileProperty.ATTRIBUTE_SOURCE)).intValue();
          // System.out.println(nvi.getID() + ":"+ source + "\t" + nvj.getID()+":"+target);

          if (((nvi.getID() == source) && (nvj.getID() == target))
              || ((nvi.getID() == target) && (nvj.getID() == source))) {
            weight = ((Float) nae.getAttribute(NETFileProperty.ATTRIBUTE_WEIGHT)).floatValue();
            // System.out.println(weight);
            break;
          } else {
            weight = (float) 0.0;
          }
        }
        pw.print(weight + " ");
      }
      pw.println();
    }
  }
示例#2
0
 private void writeVertices(ValidateNETFile vmf, PrintWriter pw) {
   pw.write(MATFileProperty.HEADER_VERTICES + " " + vmf.getVertices().size() + "\n");
   for (int i = 0; i < vmf.getVertices().size(); i++) {
     NETVertex mv = (NETVertex) vmf.getVertices().get(i);
     String s = "";
     for (int j = 0; j < NETVertex.getVertexAttributes().size(); j++) {
       try {
         NETAttribute ma = (NETAttribute) NETVertex.getVertexAttributes().get(j);
         String attr = ma.getAttrName();
         String type = ma.getDataType();
         String value = mv.getAttribute(attr).toString();
         if (value == null) {
           s += "";
         } else {
           if (NETFileFunctions.isInList(attr, noPrintParameters)) {
             if (type.equalsIgnoreCase("string")) s += "\"" + mv.getAttribute(attr) + "\" ";
             else s += mv.getAttribute(attr) + " ";
           } else {
             if (type.equalsIgnoreCase("string")) {
               if (attr.startsWith("unknown")) s += " \"" + mv.getAttribute(attr) + "\" ";
               else s += attr + " \"" + mv.getAttribute(attr) + "\" ";
             } else s += attr + " " + mv.getAttribute(attr) + " ";
           }
         }
       } catch (NullPointerException ex) {
         s += "";
       }
     }
     // System.out.println(s);
     pw.println(s);
   }
   // System.out.println("done here");
 }