this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christopher Mears <chris.mears@monash.edu> 5 * 6 * Copyright: 7 * Christopher Mears, 2012 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#include <gecode/int/ldsb.hh> 35#include <gecode/int/branch.hh> 36 37namespace Gecode { namespace Int { namespace LDSB { 38 /// Compute symmetric literals 39 template <> 40 ArgArray<Literal> 41 VariableSymmetryImp<IntView> 42 ::symmetric(Literal l, const ViewArray<IntView>& x) const { 43 (void) x; 44 if (indices.valid(l._variable) && indices.get(l._variable)) { 45 int n = 0; 46 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i) 47 n++; 48 ArgArray<Literal> lits(n); 49 int j = 0; 50 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i) 51 lits[j++] = Literal(i.val(), l._value); 52 return lits; 53 } else { 54 return ArgArray<Literal>(0); 55 } 56 } 57 /// Compute symmetric literals 58 template <> 59 ArgArray<Literal> 60 VariableSymmetryImp<BoolView> 61 ::symmetric(Literal l, const ViewArray<BoolView>& x) const { 62 (void) x; 63 if (indices.valid(l._variable) && indices.get(l._variable)) { 64 int n = 0; 65 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i) 66 n++; 67 ArgArray<Literal> lits(n); 68 int j = 0; 69 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i) 70 lits[j++] = Literal(i.val(), l._value); 71 return lits; 72 } else { 73 return ArgArray<Literal>(0); 74 } 75 } 76 77 /// Compute symmetric literals 78 template <> 79 ArgArray<Literal> 80 ValueSymmetryImp<IntView> 81 ::symmetric(Literal l, const ViewArray<IntView>& x) const { 82 (void) x; 83 if (values.valid(l._value) && values.get(l._value)) { 84 int n = 0; 85 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i) 86 n++; 87 ArgArray<Literal> lits(n); 88 int j = 0; 89 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i) 90 lits[j++] = Literal(l._variable, i.val()); 91 return lits; 92 } else { 93 return ArgArray<Literal>(0); 94 } 95 } 96 /// Compute symmetric literals 97 template <> 98 ArgArray<Literal> 99 ValueSymmetryImp<BoolView> 100 ::symmetric(Literal l, const ViewArray<BoolView>& x) const { 101 (void) x; 102 if (values.valid(l._value) && values.get(l._value)) { 103 int n = 0; 104 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i) 105 n++; 106 ArgArray<Literal> lits(n); 107 int j = 0; 108 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i) 109 lits[j++] = Literal(l._variable, i.val()); 110 return lits; 111 } else { 112 return ArgArray<Literal>(0); 113 } 114 } 115 116 /// Compute symmetric literals 117 template <> 118 ArgArray<Literal> 119 ValueSequenceSymmetryImp<Int::IntView> 120 ::symmetric(Literal l, const ViewArray<IntView>& x) const { 121 (void) x; 122 Region region; 123 Support::DynamicStack<Literal,Region> s(region); 124 std::pair<int,int> location = findVar(values, n_values, seq_size, l._value); 125 if (location.first == -1) return dynamicStackToArgArray(s); 126 unsigned int seqNum = location.first; 127 unsigned int seqPos = location.second; 128 if (! dead_sequences.get(seqNum)) { 129 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) { 130 if (seq == seqNum) continue; 131 if (dead_sequences.get(seq)) continue; 132 s.push(Literal(l._variable, getVal(seq,seqPos))); 133 } 134 } 135 return dynamicStackToArgArray(s); 136 } 137 /// Compute symmetric literals 138 template <> 139 ArgArray<Literal> 140 ValueSequenceSymmetryImp<BoolView> 141 ::symmetric(Literal l, const ViewArray<BoolView>& x) const { 142 (void) x; 143 Region region; 144 Support::DynamicStack<Literal,Region> s(region); 145 std::pair<int,int> location = findVar(values, n_values, seq_size, l._value); 146 if (location.first == -1) return dynamicStackToArgArray(s); 147 unsigned int seqNum = location.first; 148 unsigned int seqPos = location.second; 149 if (! dead_sequences.get(seqNum)) { 150 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) { 151 if (seq == seqNum) continue; 152 if (dead_sequences.get(seq)) continue; 153 s.push(Literal(l._variable, getVal(seq,seqPos))); 154 } 155 } 156 return dynamicStackToArgArray(s); 157 } 158 159}}} 160 161// STATISTICS: int-branch