Main Page | Class Hierarchy | File List

AAP.hpp

00001 // $Id: AAP.hpp,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 #ifndef _AAP_H
00013 #define _AAP_H
00014 
00015 #include "BCP_buffer.hpp"
00016 
00017 #include <string>
00018 #include <iostream>
00019 using namespace std;
00020 
00021 /*--------------------------------------------------------------------------*/
00022 //Class for storage of instance of Axial Assignment Problem (AAP)
00023 
00024 class AAP{
00025 private:
00026   int dimension;
00027   double * assigncost;
00028 
00029 public:
00030   AAP() : dimension(0), assigncost(0) {};
00031   AAP(const string & datafile);
00032   AAP(BCP_buffer & buf);
00033   ~AAP() {
00034     delete [] assigncost;
00035   }
00036 
00037 public:
00038   void pack(BCP_buffer & buf) const;
00039   void unpack(BCP_buffer & buf);  
00040   inline int      getDimension() const { return dimension; }
00041   inline double * getAssignCost() const { return assigncost; }
00042   inline int n_cols() const { return dimension * dimension * dimension; }
00043 };
00044 
00045 /*--------------------------------------------------------------------------*/
00046 //Helper Functions for AAP indexing
00047 static inline int index3(const int i, const int j, const int k, const int n){
00048   return (i * n * n) + (j * n) + k;
00049 }
00050 
00051 static inline int index2(const int i, const int j, const int n){
00052   return (i * n) + j;
00053 }
00054 
00055 static inline int ijk_i(const int index, const int n){
00056   return index / (n * n);
00057 }  
00058 
00059 static void ijk(const int index, const int n, int & i, int & j, int & k){
00060   int n_sq = (n * n);
00061   int jmod = index % n_sq;
00062   i = index / n_sq;
00063   j = jmod / n;
00064   k = jmod % n;
00065 }
00066 
00067 static void ij(const int index, const int n, int & i, int & j){
00068   int jmod = index % n;
00069   i = index / n;
00070   j = jmod;
00071 }
00072 
00073 static void ijk_print(const int index, const int n, ostream * os = &cout){
00074   int i, j, k;
00075   ijk(index, n, i, j, k);
00076   (*os) << "(" << i << "," << j << "," << k << ") ";
00077 }
00078 
00079 
00080 
00081 #endif

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