$search
00001 /* 00002 * Assignment.h 00003 * 00004 * Created on: Jul 28, 2011 00005 * Author: sdries 00006 */ 00007 00008 #include "wire/logic/AssignmentMatrix.h" 00009 #include "wire/logic/Assignment.h" 00010 00011 #include <algorithm> 00012 #include <stdio.h> 00013 00014 using namespace std; 00015 00016 namespace mhf { 00017 00018 bool compareAssignments(const Assignment* ass1, const Assignment* ass2) { 00019 return ass1->getProbability() > ass2->getProbability(); 00020 } 00021 00022 AssignmentMatrix::AssignmentMatrix() { 00023 00024 } 00025 00026 AssignmentMatrix::~AssignmentMatrix() { 00027 00028 } 00029 00030 void AssignmentMatrix::addPotentialAssignment(const Assignment& assignment) { 00031 map<const Evidence*, unsigned int>::iterator it_ev = evidence_to_index_.find(assignment.getEvidence()); 00032 00033 int ev_index; 00034 if (it_ev == evidence_to_index_.end()) { 00035 ev_index = assignments_.size(); 00036 evidence_to_index_[assignment.getEvidence()] = ev_index; 00037 assignments_.resize(ev_index + 1); 00038 } else { 00039 ev_index = it_ev->second; 00040 } 00041 00042 assignments_[ev_index].push_back(&assignment); 00043 } 00044 00045 00046 void AssignmentMatrix::sortAssignments() { 00047 for(vector<vector<const Assignment*> >::iterator it_ev = assignments_.begin(); it_ev != assignments_.end(); ++it_ev) { 00048 sort(it_ev->begin(), it_ev->end(), compareAssignments); 00049 } 00050 } 00051 00052 const Assignment& AssignmentMatrix::getAssignment(unsigned int i_ev, int i_assignment) { 00053 return *assignments_[i_ev][i_assignment]; 00054 } 00055 00056 unsigned int AssignmentMatrix::getNumAssignments(unsigned int i_ev) { 00057 return assignments_[i_ev].size(); 00058 } 00059 00060 unsigned int AssignmentMatrix::getNumMeasurements() const { 00061 return assignments_.size(); 00062 } 00063 00064 }