Generated on Fri Oct 19 11:25:01 2018 for Gecode by doxygen 1.6.3

conflict-graph.cpp

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  *  Copyright:
00007  *     Christian Schulte, 2014
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/int/bin-packing.hh>
00035 
00036 namespace Gecode { namespace Int { namespace BinPacking {
00037 
00038   ExecStatus
00039   ConflictGraph::bk(NodeSet& p, NodeSet& x) {
00040     assert(!(p.none(nodes()) && x.none(nodes())));
00041     // Iterate over neighbors of pivot node
00042     Nodes n(node[pivot(p,x)].n);
00043     // Iterate over elements of p
00044     Nodes i(p);
00045     // The loop iterates over elements in i - n
00046     while (i() < nodes()) {
00047       int iv = i(), nv = n();
00048       if ((n() < nodes()) && (iv == nv)) {
00049         ++i; ++n;
00050       } else if ((n() < nodes()) && (iv > nv)) {
00051         ++n;
00052       } else {
00053         ++i; ++n;
00054 
00055         Region reg;
00056 
00057         // Found i.val() to be in i - n
00058 
00059         NodeSet np, nx;
00060         np.allocate(reg,nodes());
00061         nx.allocate(reg,nodes());
00062 
00063         bool empty = NodeSet::iwn(np,p,nx,x,node[iv].n,nodes());
00064 
00065         p.excl(iv); x.incl(iv);
00066 
00067         // Update current clique
00068         cur.incl(iv,node[iv].w);
00069 
00070         if (empty) {
00071           // Found a max clique
00072           GECODE_ES_CHECK(clique());
00073         } else {
00074           GECODE_ES_CHECK(bk(np,nx));
00075         }
00076 
00077         // Reset current clique
00078         cur.excl(iv,node[iv].w);
00079       }
00080     }
00081     return ES_OK;
00082   }
00083 
00084 }}}
00085 
00086 // STATISTICS: int-prop
00087