Main Page | Class Hierarchy | File List

AAP_tm.cpp

00001 // $Id: AAP_tm.cpp,v 1.2 2003/12/03 01:52:30 magh Exp $
00002 
00003 /*-------------------------------------------------------------------------
00004  Author: Matthew Galati (magh@lehigh.edu)
00005 
00006  (c) Copyright 2003 Lehigh University. All Rights Reserved.
00007 
00008  This software is licensed under the Common Public License. Please see 
00009  accompanying file for terms.    
00010 ---------------------------------------------------------------------------*/
00011 
00012 #include "BCP_tm.hpp"
00013 #include "CoinHelperFunctions.hpp"
00014 #include "AAP_tm.hpp"
00015 #include "AAP_var.hpp"
00016 #include "AAP_init.hpp"
00017 #include "AAP_user_data.hpp"
00018 
00019 /*--------------------------------------------------------------------------*/
00020 void AAP_tm::pack_module_data(BCP_buffer & buf, BCP_process_t ptype){
00021   //Pack information to be passed to the LP process
00022   lp_par.pack(buf);  //the list of parameters read in
00023   aap->pack(buf);    //the AAP instance
00024 }
00025 
00026 /*--------------------------------------------------------------------------*/
00027 void AAP_tm::pack_var_algo(const BCP_var_algo* var, BCP_buffer& buf){
00028   //Pack an algorithmic variable (AAP_var is derived from BCP_var_algo)
00029   {
00030     const AAP_var * mvar = dynamic_cast<const AAP_var*>(var);
00031     if(mvar){
00032       mvar->pack(buf);
00033       return;
00034     }
00035   }
00036   throw BCP_fatal_error("AAP_tm::pack_var_algo() : unknown cut type!\n");
00037 }
00038 
00039 /*--------------------------------------------------------------------------*/
00040 BCP_var_algo* AAP_tm::unpack_var_algo(BCP_buffer& buf){
00041   //Unpack an algorithmic variable (AAP_var is derived from BCP_var_algo)
00042   return new AAP_var(buf);
00043 }
00044 
00045 /*--------------------------------------------------------------------------*/
00046 void AAP_tm::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf){
00047   //Pack user data
00048   {
00049     const AAP_user_data * data = dynamic_cast<const AAP_user_data*>(ud);
00050     if(data){
00051       data->pack(buf);
00052       return;
00053     }
00054   }
00055   throw BCP_fatal_error("AAP_tm::pack_user_data() : cast failed!\n");
00056 }
00057 
00058 /*--------------------------------------------------------------------------*/
00059 BCP_user_data * AAP_tm::unpack_user_data(BCP_buffer& buf){
00060   return new AAP_user_data(buf);
00061 }
00062 
00063 /*--------------------------------------------------------------------------*/
00064 void AAP_tm::display_feasible_solution(const BCP_solution * sol){
00065 
00066   //Display the current feasible solution
00067 #ifdef DBG_PRINT
00068   const BCP_solution_generic* gsol =
00069     dynamic_cast<const BCP_solution_generic*>(sol);
00070   if(gsol){
00071     const int varnum = gsol->_vars.size();
00072     for (int c = 0; c < varnum; ++c) {   
00073       const AAP_var* mvar = dynamic_cast<const AAP_var*>(gsol->_vars[c]);
00074       if(mvar){
00075         cout << "Column " << gsol->_vars[c]->bcpind() << " : " 
00076              << gsol->_values[c] << endl; 
00077         mvar->print(aap->getDimension());
00078       }
00079     }
00080   }
00081 #else
00082   BCP_tm_user::display_feasible_solution(sol);
00083 #endif
00084 }
00085 
00086 /*--------------------------------------------------------------------------*/
00087 void AAP_tm::initialize_core(BCP_vec<BCP_var_core*>& vars,
00088                              BCP_vec<BCP_cut_core*>& cuts,
00089                              BCP_lp_relax*& matrix) {
00090   /*
00091     Axial Assignment Problem:
00092     min {ijk in I x J x K} c_ijk x_ijk
00093     sum {jk in J x K}            x_ijk = 1, forall i in I (1)
00094     sum {ik in I x K}            x_ijk = 1, forall j in J (2)
00095     sum {ij in I x J}            x_ijk = 1, forall k in K (3)
00096     x_ijk in {0,1}, for all ijk in I x J x K              (4)
00097 
00098     Dantizg-Wolfe LP Formulation:
00099     min {s in F'}                c_s lambda_s             
00100     sum {s in F', jk in J x K} s_ijk lambda_s = 1, forall i in I (5) DUAL:uhat
00101     sum {s in F'}                    lambda_s = 1                (6) DUAL:alpha
00102 
00103     Note: 
00104     F'    = {s in Z_n : (2)(3)(4)} - an AP point (the J x K assignment)
00105     x_ijk = sum{s in F'} s_ijk lambda_s
00106     c_s   = sum{ijk in I x J x K} s_ijk c_ijk
00107   */
00108 
00109   // Here we define which variables and which constraints are core, i.e., 
00110   // those which can never be removed from the base model. We have no core 
00111   // variables. The core constraints are (5) and (6).
00112   const int n_cuts = aap->getDimension() + 1;
00113   cuts.reserve(n_cuts);
00114 
00115   // Define a core cut for each constraint in (5) and (6) with lb = ub = 1.0
00116   for(int r = 0; r < n_cuts; r++)
00117     cuts.unchecked_push_back(new BCP_cut_core(1.0, 1.0));
00118 }
00119 
00120 /*--------------------------------------------------------------------------*/
00121 void AAP_tm::create_root(BCP_vec<BCP_var*>& added_vars,
00122                          BCP_vec<BCP_cut*>& added_cuts,
00123                          BCP_user_data * & user_data,
00124                          BCP_pricing_status& pricing_status){
00125 
00126   // Here we define the root node of the search tree.
00127 
00128   // The pricing status says which type of variables need to be priced out
00129   // to find a solution. In our case we are generating algorithmic variables.
00130   // Algorithmic variables are used when there are too many to count (index).
00131   pricing_status = BCP_PriceAlgoVars;
00132 
00133   // Initialize the root node's user data
00134   user_data = new AAP_user_data();
00135   
00136   // AP Points (fix i and find an assignment for J x K)
00137   // sum {ik in I x K}            x_ijk = 1, forall j in J (2)
00138   // sum {ij in I x J}            x_ijk = 1, forall k in K (3)
00139   
00140   // Seed the root with random AP points such that we have at least one
00141   // feasible AAP point. Keep it simple for now, just use AP point: x_iii.
00142   int i, index;
00143   
00144   const double * assigncost = aap->getAssignCost();
00145   const int n = aap->getDimension();
00146 
00147   vector<int> ap;
00148   ap.reserve(n);
00149 
00150   double cost = 0.0;
00151   for(i = 0; i < n; i++){
00152     index = index3(i,i,i,n);
00153     ap.push_back(index);
00154     cost += assigncost[index];
00155   }
00156 
00157   added_vars.push_back(new AAP_var(ap, cost));
00158 }
00159 
00160 /*--------------------------------------------------------------------------*/
00161 void AAP_tm::init_new_phase(int phase, BCP_column_generation & colgen) {
00162   // Initialize the column generation phase
00163   colgen = BCP_GenerateColumns;
00164 }
00165 

Generated on Wed Dec 3 01:30:51 2003 for AAP_BP by doxygen 1.3.5