conflict-graph.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2014
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/int/bin-packing.hh>
namespace Gecode { namespace Int { namespace BinPacking {
ExecStatus
ConflictGraph::bk(NodeSet& p, NodeSet& x) {
assert(!(p.none(nodes()) && x.none(nodes())));
// Iterate over neighbors of pivot node
Nodes n(node[pivot(p,x)].n);
// Iterate over elements of p
Nodes i(p);
// The loop iterates over elements in i - n
while (i() < nodes()) {
int iv = i(), nv = n();
if ((n() < nodes()) && (iv == nv)) {
++i; ++n;
} else if ((n() < nodes()) && (iv > nv)) {
++n;
} else {
++i; ++n;
Region reg;
// Found i.val() to be in i - n
NodeSet np, nx;
np.allocate(reg,nodes());
nx.allocate(reg,nodes());
bool empty = NodeSet::iwn(np,p,nx,x,node[iv].n,nodes());
p.excl(iv); x.incl(iv);
// Update current clique
cur.incl(iv,node[iv].w);
if (empty) {
// Found a max clique
GECODE_ES_CHECK(clique());
} else {
GECODE_ES_CHECK(bk(np,nx));
}
// Reset current clique
cur.excl(iv,node[iv].w);
}
}
return ES_OK;
}
}}}
// STATISTICS: int-prop
bin-packing.hh
Gecode::Int::BinPacking::ConflictGraph::NodeSet
Sets of graph nodes.
Definition bin-packing.hh:194
Gecode::Int::BinPacking::ConflictGraph::NodeSet::incl
void incl(int i)
Include node i.
Definition conflict-graph.hpp:68
Gecode::Int::BinPacking::ConflictGraph::NodeSet::iwn
static bool iwn(NodeSet &iwa, const NodeSet &a, NodeSet &iwb, const NodeSet &b, const NodeSet &c, int n)
Definition conflict-graph.hpp:84
Gecode::Int::BinPacking::ConflictGraph::NodeSet::allocate
void allocate(Region &r, int n)
Allocate node set for n nodes.
Definition conflict-graph.hpp:56
Gecode::Int::BinPacking::ConflictGraph::NodeSet::excl
void excl(int i)
Exclude node i.
Definition conflict-graph.hpp:72
Gecode::Int::BinPacking::ConflictGraph::Nodes
Iterator over node sets.
Definition bin-packing.hh:243
Gecode::Int::BinPacking::ConflictGraph::cur
Clique cur
Current clique.
Definition bin-packing.hh:294
Gecode::Int::BinPacking::ConflictGraph::clique
ExecStatus clique(void)
Report the current clique.
Definition conflict-graph.hpp:201
Gecode::Int::BinPacking::ConflictGraph::nodes
int nodes(void) const
Return number of nodes.
Definition conflict-graph.hpp:42
Gecode::Int::BinPacking::ConflictGraph::pivot
int pivot(const NodeSet &a, const NodeSet &b) const
Find a pivot node with maximal degree from a or b.
Definition conflict-graph.hpp:175
Gecode::Int::BinPacking::ConflictGraph::node
Node * node
The nodes in the graph.
Definition bin-packing.hh:240
Gecode::Int::BinPacking::ConflictGraph::bk
ExecStatus bk(NodeSet &p, NodeSet &x)
Run Bosch-Kerbron algorithm for finding max cliques.
Definition conflict-graph.cpp:39
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::Support::RawBitSetBase::none
bool none(unsigned int sz) const
Test whether no bits are set.
Definition bitset-base.hpp:535
GECODE_ES_CHECK
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
Gecode::Int::BinPacking
Bin-packing propagators
Gecode::Int
Finite domain integers.
Gecode
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476