- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Blis-0.92.0/Alps/examples/Knap/KnapModel.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Abstract Library for Parallel Search (ALPS).     *
    00003  *                                                                           *
    00004  * ALPS is distributed under the Eclipse Public License as part of the       *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors: Yan Xu, Lehigh University                                       *
    00008  *          Ted Ralphs, Lehigh University                                    *
    00009  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00010  *          Matthew Saltzman, Clemson University                             *
    00011  *                                                                           *
    00012  *                                                                           *
    00013  * Copyright (C) 2001-2011, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00014  *===========================================================================*/
    00015
    00016 #ifndef KnapModel_h_
    00017 #define KnapModel_h_
    00018
    00019
    00020 #include "AlpsKnowledge.h"
    00021 #include "AlpsModel.h"
    00022 #include "KnapParams.h"
    00023
    00024 //#############################################################################
    00025
    00026 class KnapModel : public AlpsModel {
    00027
    00028  private:
    00029
    00031   int capacity_;
    00032
    00034   std::vector< std::pair<int, int> > items_;
    00035
    00037   int* sequence_;
    00038
    00040   KnapParams *KnapPar_;
    00041
    00042  public:
    00043
    00044   KnapModel() : capacity_(0), sequence_(0), KnapPar_(new KnapParams) {}
    00045   KnapModel(int cap, std::vector<std::pair<int, int> > items, int* seq)
    00046       :
    00047       capacity_(cap),
    00048       sequence_(seq),
    00049       KnapPar_(new KnapParams)
    00050       { items_.insert(items_.begin(), items.begin(), items.end()); }
    00051
    00052   ~KnapModel() {
    00053       if (sequence_ != 0) {
    00054           delete [] sequence_;
    00055           sequence_ = 0;
    00056       }
    00057       delete KnapPar_;
    00058   }
    00059
    00061   inline int getCapacity() const { return capacity_; }
    00062
    00064   inline int getNumItems() const { return static_cast<int> (items_.size()); }
    00065
    00067   inline int* getSequence() const { return sequence_; }
    00068
    00069 //############################################################################
    00070
    00072   virtual void readParameters(const int argnum, const char * const * arglist){
    00073       AlpsPar_->readFromArglist(argnum, arglist);
    00074       int msgLevel = AlpsPar_->entry(AlpsParams::msgLevel);
    00075       if (msgLevel > 0) {
    00076           std::cout << "Reading in KNAP parameters ..." << std::endl;
    00077           std::cout << "Reading in ALPS parameters ..." << std::endl;
    00078       }
    00079       KnapPar_->readFromArglist(argnum, arglist);
    00080   }
    00081
    00083   inline std::pair<int, int> getItem(int i) const {
    00084     return(items_[sequence_[i]]);
    00085   }
    00086
    00088   inline void setCapacity(int capacity) { capacity_ = capacity; }
    00089
    00091   void setSequence(const int * seq);
    00092
    00094   inline void addItem(int size, int cost)
    00095     { items_.push_back(std::pair<int, int>(size, cost)); }
    00096
    00098   void readInstance(const char* dataFile);
    00099
    00101   void orderItems();
    00102
    00104   virtual AlpsEncoded* encode() const;
    00105
    00108   virtual void decodeToSelf(AlpsEncoded&);
    00109 };
    00110
    00111 //#############################################################################
    00112
    00113 #endif