00001 #ifndef vsrl_dynamic_program_h 00002 #define vsrl_dynamic_program_h 00003 00004 00005 // This class will solve a dynamic program which attempts 00006 // to compute a set of assignments between two sets of tokens 00007 00008 #include <vcl_vector.h> 00009 #include <vnl/vnl_vector.h> 00010 00011 class vsrl_token; 00012 class vsrl_null_token; 00013 00014 typedef vcl_vector<vsrl_token*> token_list; 00015 00016 00017 class vsrl_dynamic_program 00018 { 00019 public: 00020 // constructor 00021 vsrl_dynamic_program(); 00022 00023 // destructor 00024 ~vsrl_dynamic_program(); 00025 00026 // set the token lists 00027 00028 void set_tokens(token_list &l1, 00029 token_list &l2); 00030 // set the inner null cost 00031 void set_inner_cost(double cost); 00032 00033 // set the outer cost null cost 00034 void set_outer_cost(double cost); 00035 00036 // set the continuity cost 00037 void set_continuity_cost(double cost); 00038 00039 // set the search range for each token 00040 00041 void set_search_range(int range); 00042 00043 // execute the dynamic program 00044 00045 double execute(); 00046 00047 void define_search_range(); 00048 00049 void define_search_range(vnl_vector<int > curr_row); 00050 00051 00052 00053 protected: 00054 00055 // this structure will keep track of possible assignments 00056 struct assignment_node{ 00057 int index1; // the first token of this assignment 00058 int index2; // the second token of this assignment 00059 int prior_index1; // the first token of the prior assignment 00060 int prior_index2; // the second token of the prior assignment 00061 double cost; // the cost of this assignment 00062 double num_null1; // the number of consecutive null assignments for this assignment 00063 }; 00064 00065 token_list list1_; // the first set of tokens 00066 token_list list2_; // the second list of tokens 00067 00068 double inner_cost_; // the cost of a missing inner assignment 00069 double outer_cost_; // the cost of a missing outer assignment 00070 double continuity_cost_; // the cost of a discontinuity 00071 int search_range_; // the search range for each token; 00072 00073 vcl_vector<int> lower_search_range_; // the search range for each token 00074 vcl_vector<int> upper_search_range_; // in the future it could be specific 00075 00076 00077 00078 assignment_node **cost_matrix_; // structure used to keep track of assignment costs 00079 int num_row_; // the number of rows in the matrix 00080 int num_col_; // the number of columns in the matrix 00081 00082 vsrl_null_token *inner_null_token_; 00083 vsrl_null_token *outer_null_token_; 00084 00085 // private functions 00086 // allocate the matrix 00087 bool allocate_cost_matrix(); 00088 00089 // deallocate the matrix 00090 void deallocate_cost_matrix(); 00091 00092 00093 // compute the cost of tokens and j 00094 void compute_cost(int i, int j); 00095 00096 // compute the optimal assignment 00097 double optimum_assignment(); 00098 00099 // **** some tools for analysis **** 00100 public: 00101 00102 void print_direct_cost(int i, int j); 00103 void print_cost(int i, int j); 00104 00105 void print_direct_costs(int i); 00106 void print_costs(int i); 00107 void print_assignment_node(int i, int j); 00108 void print_assignment_nodes(int i); 00109 00110 void print_assignment(int i); 00111 void print_assignments(); 00112 }; 00113 00114 #endif
1.5.1