Commit d9c57713 authored by Kristin Berry's avatar Kristin Berry
Browse files

Updated ControlNet to exclude edges to-and-from the same node and some cleanup!

parent 54381f2f
Loading
Loading
Loading
Loading
+46 −41
Original line number Diff line number Diff line
@@ -335,7 +335,7 @@ namespace Isis {
   *    
   * @throws IException::Programmer "NULL measure passed to ControlNet::pointAdded!"
   * @throws IException::Programmer "Control measure with NULL parent passed to
   *     ControlNet::pointAdded!"
   *     ControlNet::pointAdded"
   * @throws IException::Programmer "ControlNet does not contain the point."
   */
  void ControlNet::pointAdded(ControlPoint *point) {
@@ -377,6 +377,7 @@ namespace Isis {
          if (!cm->IsIgnored()) {
            QString sn = cm->GetCubeSerialNumber();
            
            if (QString::compare(sn, serial) != 0) {
              // If the edge doesn't already exist, this adds and returns the edge. 
              // If the edge already exists, this just returns it. (The use of a set
              // forces the edges to be unique.)
@@ -389,6 +390,7 @@ namespace Isis {
        }
      }
    }
  }


  /**
@@ -398,6 +400,7 @@ namespace Isis {
   */
  QString ControlNet::GraphToString() const {
    QString graphString; 
    
    typedef boost::graph_traits<Network>::edge_iterator edge_iter;
    edge_iter ei, ei_end;
    
@@ -428,9 +431,9 @@ namespace Isis {
        }

//        graphString.append(QString::number(m_controlGraph[targetImage].measures.size()));  
        graphString.append("] edge strength: [");
        graphString.append(QString::number(m_controlGraph[*ei].strength));
        graphString.append("]\n"); 
        graphString.append("]");// edge strength: [");
    //    graphString.append(QString::number(m_controlGraph[*ei].strength));
        graphString.append("\n"); 
      }
    }
    return graphString;
@@ -469,22 +472,17 @@ namespace Isis {
      msg += point->GetId() + "]";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    // Add the measure to the corresponding node
    QString serial = measure->GetCubeSerialNumber();

    // Make sure there is a node for every measure in this measure's parent
    for (int i = 0; i < point->GetNumMeasures(); i++) {
      QString sn = point->GetMeasure(i)->GetCubeSerialNumber();

      // If the graph doesn't have the sn, add the node.
      if (!m_vertexMap.contains(sn)) {
    // If the graph doesn't have the sn, add a node for it
    if (!m_vertexMap.contains(serial)) {
      Image newImage;
        newImage.serial = sn; 
      newImage.serial = serial; 
      ImageVertex newVertex = boost::add_vertex(newImage, m_controlGraph); 
        m_vertexMap.insert(sn, newVertex);
      }
      m_vertexMap.insert(serial, newVertex);
    }

    // Add the measure to the corresponding node
    QString serial = measure->GetCubeSerialNumber();
    m_controlGraph[m_vertexMap[serial]].measures[measure->Parent()] = measure; 

    // in this measure's node add connections to the other nodes reachable from
@@ -495,6 +493,8 @@ namespace Isis {
        if (!cm->IsIgnored()) {
          QString sn = cm->GetCubeSerialNumber();


          if (QString::compare(sn, serial) != 0) {
            // If the edge doesn't already exist, this adds and returns the edge. 
            // If the edge already exists, this just returns it. (The use of a set
            // forces the edges to be unique.)
@@ -506,6 +506,8 @@ namespace Isis {
        }
      }
    }
  }



  /**
@@ -560,6 +562,7 @@ namespace Isis {
        if (!cm->IsIgnored()) {
          QString sn = cm->GetCubeSerialNumber();

          if (QString::compare(sn, serial) != 0) {
            // If the edge doesn't already exist, this adds and returns the edge. 
            // If the edge already exists, this just returns it. (The use of a set
            // forces the edges to be unique.)
@@ -571,6 +574,7 @@ namespace Isis {
        }
      }
    }
  }


  /**
@@ -612,12 +616,13 @@ namespace Isis {
    m_controlGraph[m_vertexMap[serial]].measures.remove(measure->Parent()); 


// We decided in a meeting that we do not want to delete the node when all measures are removed. 
    // If this caused the node to be empty, then delete the node.
    if (m_controlGraph[m_vertexMap[serial]].measures.size() <= 0) {
      boost::clear_vertex(m_vertexMap[serial], m_controlGraph);
      boost::remove_vertex(m_vertexMap[serial], m_controlGraph);
      m_vertexMap.remove(serial);
    }
//    if (m_controlGraph[m_vertexMap[serial]].measures.size() <= 0) {
//      boost::clear_vertex(m_vertexMap[serial], m_controlGraph);
//      boost::remove_vertex(m_vertexMap[serial], m_controlGraph);
//      m_vertexMap.remove(serial);
//    }
  }


+33 −90
Original line number Diff line number Diff line
UnitTest for ControlNet ....

******* test cube connection graph ************
  ALPHA
    BRAVO :  p0
  BRAVO
    ALPHA :  p0
ALPHA [p0] --------- BRAVO [p0]

  ALPHA
ALPHA [p0] --------- BRAVO [p0]

  BRAVO
ALPHA [p0] --------- BRAVO [p0]

testing measure addition to point already in network...
ALPHA [p1, p0] --------- BRAVO [p0]

  ALPHA
    BRAVO :  p0
  BRAVO
    ALPHA :  p0
ALPHA [p1, p0] --------- BRAVO [p1, p0]

testing measure addition to point already in network...
  ALPHA
    BRAVO :  p0, p1
    CHARLIE :  p1
  BRAVO
    ALPHA :  p0, p1
    CHARLIE :  p1
  CHARLIE
    ALPHA :  p1
    BRAVO :  p1
ALPHA [p1, p0] --------- BRAVO [p1, p0]
CHARLIE [p1] --------- ALPHA [p1, p0]
CHARLIE [p1] --------- BRAVO [p1, p0]

testing setting point to ignored.......................
  ALPHA
    BRAVO :  p0
  BRAVO
    ALPHA :  p0
  CHARLIE
ALPHA [p1, p0] --------- BRAVO [p1, p0]


  ALPHA
    BRAVO :  p0, p1
    CHARLIE :  p1
  BRAVO
    ALPHA :  p0, p1
    CHARLIE :  p1
  CHARLIE
    ALPHA :  p1
    BRAVO :  p1
ALPHA [p1, p0] --------- BRAVO [p1, p0]
ALPHA [p1, p0] --------- CHARLIE [p1]
CHARLIE [p1] --------- BRAVO [p1, p0]

testing measure deletion & addition....................
  ALPHA
    BRAVO :  p1
    CHARLIE :  p1
  BRAVO
    ALPHA :  p1
    CHARLIE :  p1
  CHARLIE
    ALPHA :  p1
    BRAVO :  p1
ALPHA [p1, p0] --------- BRAVO [p1]
ALPHA [p1, p0] --------- CHARLIE [p1]
CHARLIE [p1] --------- BRAVO [p1]

  ALPHA
    BRAVO :  p1
    CHARLIE :  p1
    DELTA :  p0
  BRAVO
    ALPHA :  p1
    CHARLIE :  p1
  CHARLIE
    ALPHA :  p1
    BRAVO :  p1
  DELTA
    ALPHA :  p0
ALPHA [p1, p0] --------- BRAVO [p1]
ALPHA [p1, p0] --------- CHARLIE [p1]
CHARLIE [p1] --------- BRAVO [p1]
DELTA [p0] --------- ALPHA [p1, p0]

testing FindClosest....................
Closest Point ID: p1
testing point deletion.................................
  ALPHA
    DELTA :  p0
  DELTA
    ALPHA :  p0
DELTA [p0] --------- ALPHA [p0]

******* Done testing cube graph ***************


testing GetCubeSerials... (NOTE: unittest sorts the results)
  ALPHA
  BRAVO
  CHARLIE
  DELTA

testing set target.................................
@@ -364,45 +329,23 @@ Writing ControlNet to temp2.bin in binary format
Reading ControlNet from temp2.bin
Diffing temp.bin and temp2.bin
Read/Write of binary files OK.
Testing GetCubeGraphNodes
    ALPHA
    BRAVO
    CHARLIE
    DELTA
DELTA [p0] --------- ALPHA [p0]

Testing getGraphNode: ALPHA

Testing getEdgeCount: 2
Testing getEdgeCount: 1
Getting measures in cube with SN: ALPHA: 
Serial Number: ALPHA
Testing GetSerialConnections

Testing GetNodeConnections()
Testing GetSerialConnections()
  Island Count = 2

Testing MinimumSpanningTree()
  Tree Count = 2
  Graph Node Count = 5
  Measure Count = 9
  Island Count == 2 == MST Count

  Minimum Spanning Tree 0
    Nodes = 4
    Included Measures = 5
      m1 (ALPHA -> p1, residual = 1.41421)
      m2 (BETA -> p1, residual = 2.82843)
      m3 (GAMMA -> p1, residual = 4.24264)
      m6 (DELTA -> p3, residual = 4.24264)
      m7 (ALPHA -> p3, residual = 5.65685)
    Excluded Measures = 3
      m4 (GAMMA -> p2, residual = 1.41421)
      m5 (DELTA -> p2, residual = 11.3137)
      m8 (ALPHA -> p4, residual = 1.41421)

  Minimum Spanning Tree 1
    Nodes = 1
    Included Measures = 0
    Excluded Measures = 1
      m9 (EPSILON -> p5, residual = 1.41421)

Testing take() functionality to take owernship of the points in a ControlNet:
Original control net number of points: 1
Number of points taken out: 1
Now there should be zero points in the original control net. There are: 0
And zero pointIDs in the original control net. There are: 0
And zero cubeGraphNodes in the original control net. There are: 0
+9 −9
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ void testConnectivity() {
  net.AddPoint(p4);
  net.AddPoint(p5);

  std::cout << "Getting measures in cube: " << std::endl; 
  std::cout << "Getting measures in cube with SN: ALPHA: " << std::endl; 
  QList< ControlMeasure *> measures = net.GetMeasuresInCube("ALPHA");
  std::cout << "Serial Number: " << measures[0]->GetCubeSerialNumber() << std::endl; 

@@ -194,7 +194,9 @@ int main() {
  p1m1->SetCubeSerialNumber("BRAVO");
  ControlMeasure *p1m2 = new ControlMeasure;
  p1m2->SetCubeSerialNumber("CHARLIE");
  cout << net.GraphToString() << "\n";
  p1->Add(p1m1);
  cout << net.GraphToString() << "\n";
  p1->Add(p1m2);
  cout << net.GraphToString() << "\n";

@@ -484,17 +486,15 @@ int main() {
  remove("temp.bin");
  remove("temp2.bin");

/*  QList< ControlCubeGraphNode * > graphnodes = net.GetCubeGraphNodes();
  QList< QString > graphSNs = net.GetCubeSerials();
  // Use this to sort the output
  QList<QString> sortedSNs;
  foreach ( ControlCubeGraphNode * node, graphnodes ) {
    sortedSNs.append(node->getSerialNumber());
  }
  sort(sortedSNs.begin(), sortedSNs.end());
  foreach ( QString sn, sortedSNs ) {
  sort(graphSNs.begin(), graphSNs.end());
  foreach ( QString sn, graphSNs ) {
    cout << "    " << sn << "\n";
  }*/
  }


  cout << net.GraphToString() << endl; 
  cout << "\nTesting getEdgeCount: " << net.getEdgeCount() << "\n";

  testConnectivity();