Generated on Fri Mar 20 15:56:05 2015 for Gecode by doxygen 1.6.3

bin-packing.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Stefano Gualandi <stefano.gualandi@gmail.com>
00008  *
00009  *  Copyright:
00010  *     Stefano Gualandi, 2013
00011  *     Christian Schulte, 2010
00012  *
00013  *  Last modified:
00014  *     $Date: 2014-08-28 14:29:11 +0200 (Thu, 28 Aug 2014) $ by $Author: schulte $
00015  *     $Revision: 14203 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #ifndef __GECODE_INT_BIN_PACKING_HH__
00043 #define __GECODE_INT_BIN_PACKING_HH__
00044 
00045 #include <gecode/int.hh>
00046 
00052 namespace Gecode { namespace Int { namespace BinPacking {
00053 
00057   class Item : public DerivedView<IntView> {
00058   protected:
00059     using DerivedView<IntView>::x;
00061     int s;
00062   public:
00064     Item(void);
00066     Item(IntView b, int s);
00067 
00069     IntView bin(void) const;
00071     void bin(IntView b);
00073     int size(void) const;
00075     void size(int s);
00076 
00078     void update(Space& home, bool share, Item& i);
00079   };
00080 
00082   bool same(const Item& i, const Item& j);
00084   bool before(const Item& i, const Item& j);
00085 
00087   bool operator <(const Item& i, const Item& j);
00088 
00089 
00091   class SizeSet {
00092   protected:
00094     int n;
00096     int t;
00098     int* s;
00099   public:
00101     SizeSet(void);
00103     SizeSet(Region& region, int n_max);
00105     void add(int s);
00107     int card(void) const;
00109     int total(void) const;
00111     int operator [](int i) const;
00112   };
00113 
00115   class SizeSetMinusOne : public SizeSet {
00116   protected:
00118     int p;
00119   public:
00121     SizeSetMinusOne(void);
00123     SizeSetMinusOne(Region& region, int n);
00125     void minus(int s);
00127     int card(void) const;
00129     int total(void) const;
00131     int operator [](int i) const;
00132   };
00133 
00134 
00145   class Pack : public Propagator {
00146   protected:
00148     ViewArray<OffsetView> l;
00150     ViewArray<Item> bs;
00152     int t;
00154     Pack(Home home, ViewArray<OffsetView>& l, ViewArray<Item>& bs);
00156     Pack(Space& home, bool share, Pack& p);
00157   public:
00159     GECODE_INT_EXPORT 
00160     static ExecStatus post(Home home, 
00161                            ViewArray<OffsetView>& l, ViewArray<Item>& bs);
00163     template<class SizeSet>
00164     bool nosum(const SizeSet& s, int a, int b, int& ap, int& bp);
00166     template<class SizeSet>
00167     bool nosum(const SizeSet& s, int a, int b);
00169     GECODE_INT_EXPORT 
00170     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00172     GECODE_INT_EXPORT 
00173     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00175     GECODE_INT_EXPORT 
00176     virtual Actor* copy(Space& home, bool share);
00178     virtual size_t dispose(Space& home);
00179   };
00180 
00181 
00183   class ConflictGraph {
00184   protected:
00186     Space& home;
00188     const IntVarArgs& b;
00190     unsigned int bins;
00192     int nodes(void) const;
00193 
00195     class NodeSet : public Support::RawBitSetBase {
00196     public:
00198       NodeSet(void);
00200       NodeSet(Region& r, int n);
00202       NodeSet(Region& r, int n, const NodeSet& ns);
00204       void allocate(Region& r, int n);
00206       void init(Region& r, int n);
00208       bool in(int i) const;
00210       void incl(int i);
00212       void excl(int i);
00214       void copy(int n, const NodeSet& ns);
00216       void empty(int n);
00223       static bool iwn(NodeSet& iwa, const NodeSet& a, 
00224                       NodeSet& iwb, const NodeSet& b,
00225                       const NodeSet& c, int n);
00226     };
00227 
00229     class Node {
00230     public:
00232       NodeSet n;
00234       unsigned int d;
00236       unsigned int w;
00238       Node(void);
00239     };
00241     Node* node;
00242 
00244     class Nodes {
00245     private:
00247       const NodeSet& ns;
00249       unsigned int c;
00250     public:
00252       Nodes(const NodeSet& ns);
00254 
00255 
00256       void operator ++(void);
00258       
00260 
00261 
00262       int operator ()(void) const;
00264     };
00265     
00267 
00268 
00269     class Clique {
00270     public:
00272       NodeSet n;
00274       unsigned int c;
00276       unsigned int w;
00278       Clique(Region& r, int m);
00280       void incl(int i, unsigned int w);
00282       void excl(int i, unsigned int w);
00283     };
00284 
00286     int pivot(const NodeSet& a, const NodeSet& b) const;
00288     GECODE_INT_EXPORT
00289     ExecStatus bk(NodeSet& p, NodeSet& x);
00291 
00293 
00294 
00295     Clique cur;
00297     Clique max;
00299     ExecStatus clique(void);
00301     ExecStatus clique(int i);
00303     ExecStatus clique(int i, int j);
00305     ExecStatus clique(int i, int j, int k);
00307   public:
00309     ConflictGraph(Space& home, Region& r, const IntVarArgs& b,
00310                   int m);
00312     void edge(int i, int j, bool add=true);
00314     bool adjacent(int i, int j) const;
00316     ExecStatus post(void);
00318     IntSet maxclique(void) const;
00320     ~ConflictGraph(void);
00321   };
00322 
00323 }}}
00324 
00325 #include <gecode/int/bin-packing/propagate.hpp>
00326 #include <gecode/int/bin-packing/conflict-graph.hpp>
00327 
00328 #endif
00329 
00330 // STATISTICS: int-prop
00331