Roulette.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00030 
00031 #ifndef __ROULETTE_H_
00032 #define __ROULETTE_H_
00033 
00034 #ifdef MIP_HOST_APPLE
00035 #include <applePatch.h>
00036 #endif
00037 
00038 #include <vector>
00039 #include <map>
00040 #include <sstream>
00041 
00042 #include <Types.h>
00043 
00044 
00048 
00050 /* @{ */
00051 
00052 using namespace std;
00053 
00054  namespace MipBaselib {
00055 
00059  struct Pocket{
00060   
00062   int value;
00063   
00065   Decimal weight;
00066   
00069   Pocket();
00070   
00074   Pocket(int v);
00075   
00080   Pocket(int v, Decimal w);
00081   
00084   Pocket(const Pocket& v);
00085   
00088   const Pocket& operator=(const Pocket& v);
00089   
00092   string print();
00093  };
00094 
00095 
00100  class Roulette : private vector<Pocket>{
00101   
00102   Decimal _sumW;
00103   int _numP;
00104   vector<Decimal> _pSumW;
00105   map<int,bool> _alreadyGone;
00106   int _alreadyGoneNumber;
00107   Decimal _sumGone;
00108   
00109   public:
00111    Roulette();
00112    
00114    Roulette(const Roulette &r);
00115    
00117    const Roulette& operator=(const Roulette &r);
00118    
00120    void setCapacity(int s);
00121    
00126    void addPocket(Pocket p);
00127    
00130    int getNumPockets() const;
00131    
00134    int getSumPockets() const;
00135    
00140    bool weigthedExtraction(int &extracted, bool rep = true);
00141    
00147    bool unweigthedExtraction(int &extracted, bool rep = true);
00148    
00150    void resetRepetitions();
00151    
00153    void clearAll();
00154    
00157    string print();
00158    
00159   private:
00160    bool weigthedExtractionWithRepetitions(int &extracted);
00161    
00162    bool unweigthedExtractionWithRepetitions(int &extracted);
00163    
00164    bool weigthedExtractionNoRepetitions(int &extracted);
00165    
00166    bool unweigthedExtractionNoRepetitions(int &extracted);
00167  };
00168 
00169 }; // end of namespace
00170 
00171 #endif
00172 
00173 /* @} */
00174 
00175 
00176 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6