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

sym-imp.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <chris.mears@monash.edu>
00005  *
00006  *  Copyright:
00007  *     Christopher Mears, 2012
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/ldsb.hh>
00035 #include <gecode/int/branch.hh>
00036 
00037 namespace Gecode { namespace Int { namespace LDSB {
00039   template <>
00040   ArgArray<Literal>
00041   VariableSymmetryImp<IntView>
00042   ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00043     (void) x;
00044     if (indices.valid(l._variable) && indices.get(l._variable)) {
00045       int n = 0;
00046       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00047         n++;
00048       ArgArray<Literal> lits(n);
00049       int j = 0;
00050       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00051         lits[j++] = Literal(i.val(), l._value);
00052       return lits;
00053     } else {
00054       return ArgArray<Literal>(0);
00055     }
00056   }
00058   template <>
00059   ArgArray<Literal>
00060   VariableSymmetryImp<BoolView>
00061   ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00062     (void) x;
00063     if (indices.valid(l._variable) && indices.get(l._variable)) {
00064       int n = 0;
00065       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00066         n++;
00067       ArgArray<Literal> lits(n);
00068       int j = 0;
00069       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00070         lits[j++] = Literal(i.val(), l._value);
00071       return lits;
00072     } else {
00073       return ArgArray<Literal>(0);
00074     }
00075   }
00076 
00078   template <>
00079   ArgArray<Literal>
00080   ValueSymmetryImp<IntView>
00081   ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00082     (void) x;
00083     if (values.valid(l._value) && values.get(l._value)) {
00084       int n = 0;
00085       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00086         n++;
00087       ArgArray<Literal> lits(n);
00088       int j = 0;
00089       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00090         lits[j++] = Literal(l._variable, i.val());
00091       return lits;
00092     } else {
00093       return ArgArray<Literal>(0);
00094     }
00095   }
00097   template <>
00098   ArgArray<Literal>
00099   ValueSymmetryImp<BoolView>
00100   ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00101     (void) x;
00102     if (values.valid(l._value) && values.get(l._value)) {
00103       int n = 0;
00104       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00105         n++;
00106       ArgArray<Literal> lits(n);
00107       int j = 0;
00108       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00109         lits[j++] = Literal(l._variable, i.val());
00110       return lits;
00111     } else {
00112       return ArgArray<Literal>(0);
00113     }
00114   }
00115 
00117   template <>
00118   ArgArray<Literal>
00119   ValueSequenceSymmetryImp<Int::IntView>
00120   ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00121     (void) x;
00122     Region region;
00123     Support::DynamicStack<Literal,Region> s(region);
00124     std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00125     if (location.first == -1) return dynamicStackToArgArray(s);
00126     unsigned int seqNum = location.first;
00127     unsigned int seqPos = location.second;
00128     if (! dead_sequences.get(seqNum)) {
00129       for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00130         if (seq == seqNum) continue;
00131         if (dead_sequences.get(seq)) continue;
00132         s.push(Literal(l._variable, getVal(seq,seqPos)));
00133       }
00134     }
00135     return dynamicStackToArgArray(s);
00136   }
00138   template <>
00139   ArgArray<Literal>
00140   ValueSequenceSymmetryImp<BoolView>
00141   ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00142     (void) x;
00143     Region region;
00144     Support::DynamicStack<Literal,Region> s(region);
00145     std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00146     if (location.first == -1) return dynamicStackToArgArray(s);
00147     unsigned int seqNum = location.first;
00148     unsigned int seqPos = location.second;
00149     if (! dead_sequences.get(seqNum)) {
00150       for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00151         if (seq == seqNum) continue;
00152         if (dead_sequences.get(seq)) continue;
00153         s.push(Literal(l._variable, getVal(seq,seqPos)));
00154       }
00155     }
00156     return dynamicStackToArgArray(s);
00157   }
00158 
00159 }}}
00160 
00161 // STATISTICS: int-branch