/home/coin/SVN-release/OS-2.2.0/OS/examples/branchCutPriceTSP/Member/OS_packer.cpp

Go to the documentation of this file.
00001 // Last edit: 5/20/07
00002 //
00003 // Name:     OS_packer.cpp
00004 // Author:   Francois Margot
00005 //           Tepper School of Business
00006 //           Carnegie Mellon University, Pittsburgh, PA 15213
00007 //           email: fmargot@andrew.cmu.edu
00008 // Date:     5/18/07
00009 //-----------------------------------------------------------------------------
00010 // Copyright (C) 2007, Francois Margot, IBM and others.  All Rights Reserved.
00011 
00012 #include "BCP_buffer.hpp"
00013 #include "OS_cut.hpp"
00014 #include "OS_var.hpp"
00015 #include "OS_user_data.hpp"
00016 #include "OS_packer.hpp"
00017 
00018 using namespace std;
00019 
00020 /****************************************************************************/
00021 
00022 void OS_packer::pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf) {
00023         // we don't have indexed cuts so simplify
00024  // int typ;
00025   const OS_cut* bb_cut = dynamic_cast<const OS_cut*>(cut);
00026   //if (bb_cut) {
00027    // typ = 1;
00028    // buf.pack(typ);
00029  // std::cout << "INSIDE pack_cut_algo " << std::endl;
00030     bb_cut->pack(buf);
00031     return;
00032   //}
00033   throw BCP_fatal_error("OS_pack_cut(): unknown cut type.");
00034 }
00035 
00036 /****************************************************************************/
00037 
00038 BCP_cut_algo*  OS_packer::unpack_cut_algo(BCP_buffer& buf)
00039 {
00040         // we don't have indexed cuts so simplify
00041         //int typ;
00042         //buf.unpack(typ);
00043         //switch (typ) {
00044         //case 0:
00045         //      throw BCP_fatal_error("OS_unpack_cut(): unknown cut type.");
00046     //return new OS_indexed_cut(buf);
00047         //case 1:
00048         //std::cout << "INSIDE unpack_cut_algo " << std::endl;
00049         
00050         return new OS_cut( buf);
00051         //default:
00052         //      throw BCP_fatal_error("OS_unpack_cut(): unknown cut type.");
00053    // break;
00054  // }
00055   //return NULL; // fake return
00056 }
00057 
00058 
00059 
00060 void OS_packer::pack_var_algo(const BCP_var_algo* var, BCP_buffer& buf) {
00061 
00062     const OS_var* v = dynamic_cast<const OS_var*>(var);
00063     // don't worry about type, only one kind of variable
00064         //int type = 0;
00065         //buf.pack( type);
00066 
00067         v->pack( buf);
00068         return;
00069 
00070 }
00071 
00072 /*---------------------------------------------------------------------------*/
00073 
00074 BCP_var_algo* OS_packer::unpack_var_algo(BCP_buffer& buf) {
00075 
00076         
00077    // int type;
00078    // buf.unpack( type);
00079     
00080     return new OS_var(  buf);
00081 
00082 }
00083 
00084 
00085 
00086 /****************************************************************************/
00087 
00088 void  OS_packer::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf)
00089 // Normally, no modifications required.
00090 {
00091   const MY_user_data *mud = dynamic_cast<const MY_user_data*> (ud);
00092   if(!mud)
00093     throw BCP_fatal_error("OS_lp::pack_user_data() : unknown data type!\n");
00094   
00095   printf("OS_lp::pack_user_data:\n");
00096   mud->print();
00097   mud->pack(buf);
00098 }
00099 
00100 /****************************************************************************/
00101 
00102 BCP_user_data*  OS_packer::unpack_user_data(BCP_buffer& buf)
00103   // Normally, no modifications required.
00104 {
00105   MY_user_data *p_ud = new MY_user_data(buf);
00106   printf("OS_lp::unpack_user_data:\n");
00107   p_ud->print();
00108 
00109   if (p_ud->is_processed) {
00110     p_ud->p_rud = NULL;
00111     delete(p_ud);
00112     p_ud = NULL;
00113     printf("user_data deleted\n");
00114   }
00115 
00116   return(p_ud); 
00117 }

Generated on Thu Aug 5 03:02:58 2010 by  doxygen 1.4.7