예제 #1
0
  private void writeDirectedMatrix(ValidateNETFile vmf, PrintWriter pw) {
    NETVertex nvi;
    NETVertex nvj;
    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.getArcs().size(); k++) {
          nae = (NETArcsnEdges) vmf.getArcs().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)) {
            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");
 }