Пример #1
0
  private SocialPerson createPerson(VertexRecord record, SQLDumpReader sqlData) {
    Person matsimPerson = PersonImpl.createPerson(Id.create(record.id, Person.class));
    SocialPerson person = new SocialPerson(matsimPerson);

    int age;
    if (record.isEgo) age = sqlData.getEgoAge(record.egoSQLId);
    else age = sqlData.getAlterAge(record.alterKeys);

    if (age < 0) errLogger.logNoAge(record.isEgo);
    else PersonUtils.setAge(matsimPerson, age);

    String sex = sqlData.getSex(record);
    if (sex != null) PersonUtils.setSex(matsimPerson, sex);
    else errLogger.logNoSex(record.isEgo);

    if (record.isEgo) PersonUtils.setLicence(matsimPerson, sqlData.getLicense(record));

    if (record.isEgo) PersonUtils.setCarAvail(matsimPerson, sqlData.getCarAvail(record));

    person.setCitizenship(sqlData.getCitizenship(record));
    person.setEducation(sqlData.getEducation(record));
    person.setIncome(sqlData.getIncome(record));
    person.setCivilStatus(sqlData.getCivilStatus(record));
    return person;
  }
Пример #2
0
  public SampledGraphProjection<SocialSparseGraph, SocialSparseVertex, SocialSparseEdge> buildGraph(
      List<String> alterTables, List<String> egoTables, List<String> sqlDumps) throws IOException {
    errLogger = new ErrorLogger();
    /*
     * Load raw data.
     */
    AlterTableReader alterReader = new AlterTableReader(alterTables);
    EgoTableReader egoReader = new EgoTableReader(egoTables);
    SQLDumpReader sqlReader = new SQLDumpReader(sqlDumps);
    /*
     * Build the raw graph and a sampled projection.
     */
    graph = builder.createGraph();
    proj = projBuilder.createGraph(graph);
    /*
     * Create the vertices.
     */
    projMap = new HashMap<SocialSparseVertex, SampledVertexDecorator<SocialSparseVertex>>();
    idMap = new HashMap<String, SocialSparseVertex>();

    for (Entry<String, VertexRecord> entry : alterReader.getVertices().entrySet()) {
      VertexRecord vRecord = entry.getValue();
      /*
       * Extract the home location.
       */
      Point point;
      if (vRecord.isEgo) {
        point = sqlReader.getEgoLocation(vRecord.egoSQLId);
        if (point == null) {
          /*
           * try getting coordinates via google
           */
          logger.info("Requesting google server for coordinates.");
          point = egoReader.getEgoLocation(vRecord.id);
        }
      } else {
        point = sqlReader.getAlterLocation(vRecord.alterKeys);
      }
      if (point == null) {
        errLogger.logNoCoordinate(vRecord.isEgo);
        //				point = geoFacotry.createPoint(new Coordinate(0, 0));
      }
      /*
       * Create a vertex and its projection.
       */
      SocialSparseVertex vertex = builder.addVertex(graph, createPerson(vRecord, sqlReader), point);
      SampledVertexDecorator<SocialSparseVertex> vProj = projBuilder.addVertex(proj, vertex);
      /*
       * If it is an ego set the snowball attributes.
       */
      if (vRecord.isEgo) {
        vProj.sample(infereIterationSampled(new Integer(vRecord.id)));
        vProj.detect(vProj.getIterationSampled() - 1);
      }

      projMap.put(vertex, vProj);
      idMap.put(vRecord.id, vertex);
      //			recordMap.put(vRecord.id, vRecord);
    }
    /*
     * Create the edges.
     */
    for (Tuple<VertexRecord, VertexRecord> edge : alterReader.getEdges()) {
      SocialSparseVertex v1 = idMap.get(edge.getFirst().id);
      SocialSparseVertex v2 = idMap.get(edge.getSecond().id);
      SocialSparseEdge socialEdge = builder.addEdge(graph, v1, v2);
      /*
       * Check if we have double edges.
       */
      if (socialEdge != null) {
        SampledVertexDecorator<SocialSparseVertex> vProj1 = projMap.get(v1);
        SampledVertexDecorator<SocialSparseVertex> vProj2 = projMap.get(v2);

        projBuilder.addEdge(proj, vProj1, vProj2, socialEdge);
        /*
         * Set the snowball attributes if it is not an ego.
         */
        if (!vProj1.isSampled()) {
          if (vProj1.isDetected())
            /*
             * If this vertex is already detected check if the adjacent vertex has been sampled earlier.
             */
            vProj1.detect(Math.min(vProj1.getIterationDetected(), vProj2.getIterationSampled()));
          else vProj1.detect(vProj2.getIterationSampled());
        }

        if (!vProj2.isSampled()) {
          if (vProj2.isDetected())
            /*
             * If this vertex is already detected check if the adjacent vertex has been sampled earlier.
             */
            vProj2.detect(Math.min(vProj2.getIterationDetected(), vProj1.getIterationSampled()));
          else vProj2.detect(vProj1.getIterationSampled());
        }
        /*
         * add edge attributes
         */
        VertexRecord rec1 = edge.getFirst();
        VertexRecord rec2 = edge.getSecond();
        double freq = 0;
        if (rec1.isEgo) {
          freq = sqlReader.getF2FFrequencey(rec1.egoSQLId, rec2.alterKeys.get(rec1.egoSQLId));
        } else {
          freq = sqlReader.getF2FFrequencey(rec2.egoSQLId, rec1.alterKeys.get(rec2.egoSQLId));
        }
        socialEdge.setFrequency(freq);

        socialEdge.setType(sqlReader.getEdgeType(rec1, rec2));

      } else {
        errLogger.logDoubleEdge();
      }
    }
    /*
     * Sociogram
     */
    loadSociogramData(alterReader.getVertices().values(), sqlReader);

    logger.info(errLogger.toString());
    return proj;
  }