politopix  4.1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Neighbours_Rn.h
Go to the documentation of this file.
1 // politopix allows to make computations on polytopes such as finding vertices, intersecting, Minkowski sums, ...
2 // Copyright (C) 2014-2015 : Delos Vincent
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
19 // I2M (UMR CNRS 5295 / University of Bordeaux)
20 
21 #ifndef NEIGHBOURS_Rn
22 #define NEIGHBOURS_Rn
23 #include "HalfSpace_Rn.h"
24 
25 
60 
61 public:
63 
70  const std::vector< unsigned int >& commonFacets,
71  unsigned int numbergenIN,
72  unsigned int numbergenOUT,
73  HalfSpace_Rn::State state) {
74 
75  //std::cout << std::endl << "DUMP CANDIDATE:" << std::endl;
76  //std::cout << "Gin candidate: " << numbergenIN << " ";
77  //std::cout << ", Gout candidate: " << numbergenOUT << std::endl;
78  //dump(std::cout);
79  bool alreadyInsertedPair=false;
80  {for (unsigned int i=0; i<_HSPerNewGenerators.size(); ++i) {
81  if (_HSPerNewGenerators[i].size() > commonFacets.size()) {
82  // Larger set first.
83  if (std::includes(_HSPerNewGenerators[i].begin(), _HSPerNewGenerators[i].end(), commonFacets.begin(), commonFacets.end())) {
84  // No need to do anything as the current generator set of
85  // half-spaces is included in the set number j.
86  //std::cout << "false1 (size=" << i << ")" << std::endl;
87  return;
88  }
89  }
90  else {
91  if (std::includes(commonFacets.begin(), commonFacets.end(), _HSPerNewGenerators[i].begin(), _HSPerNewGenerators[i].end())) {
92  // Substitute the old generator to be removed with the current one.
93  if (alreadyInsertedPair == false) {
94  _HSPerNewGenerators[i] = commonFacets;
95  _GeneratorsInNumber[i] = numbergenIN;
96  _GeneratorsOutNumber[i] = numbergenOUT;
97  _GeneratorsState[i] = state;
98  alreadyInsertedPair = true;
99  }
100  else {
101  // This case is rare but can occur, when we need to erase two generators already
102  // in the list. Take care of not inserting twice the same so shift the arrays.
103  {for (unsigned int ii=i; ii<_HSPerNewGenerators.size()-1; ++ii) {
108  }}
109  _GeneratorsOutNumber.pop_back();
110  _GeneratorsInNumber.pop_back();
111  _HSPerNewGenerators.pop_back();
112  _GeneratorsState.pop_back();
113  }
114  }
115  }
116  }}
117  if (alreadyInsertedPair == false) {
118  _GeneratorsInNumber.push_back(numbergenIN);
119  _GeneratorsOutNumber.push_back(numbergenOUT);
120  _HSPerNewGenerators.push_back(commonFacets);
121  _GeneratorsState.push_back(state);
122  //std::cout << "true (total=" << _HSPerNewGenerators.size() << std::endl;
123  }
124  //dump(std::cout);
125  }
126 
129 
131  void next() {++_iterator; checkIterator();}
132 
134  void checkIterator() {
136  ++_iterator;
137  }
138 
140  bool end() {return (_iterator==_HSPerNewGenerators.size());}
141 
144 
147 
149  void dump(std::ostream &ofs) {
150  ofs << "New gen:" << std::endl;
151  unsigned int i=0;
152  std::vector< std::vector< unsigned int > >::const_iterator ite;
153  for (ite=_HSPerNewGenerators.begin(); ite!=_HSPerNewGenerators.end(); ++ite) {
154  ofs << "(Gin= " << _GeneratorsInNumber[i] << ",";
155  ofs << " Gout= " << _GeneratorsOutNumber[i] << ") ";
156  ofs << "(State=" << HalfSpace_Rn::getStateAsText(_GeneratorsState[i]) << ")" << std::endl;
157  i++;
158  std::copy((*ite).begin(), (*ite).end(), std::ostream_iterator< unsigned int >(ofs, " ") );
159  ofs << std::endl;
160  }
161  }
162 
163 protected:
165  unsigned int _iterator;
167  std::vector< HalfSpace_Rn::State > _GeneratorsState;
169  std::vector< unsigned int > _GeneratorsInNumber;
171  std::vector< unsigned int > _GeneratorsOutNumber;
173  std::vector< std::vector< unsigned int > > _HSPerNewGenerators;
174 };
175 
176 #endif
void next()
Iterator function.
void begin()
Iterator function.
bool end()
Iterator function.
Class dedicated to degeneration processing when looking for neighbours. Let A be a polytope of wher...
Definition: Neighbours_Rn.h:59
unsigned int currentGenOutNumber()
Iterator function.
void checkIterator()
Make sure we don't point on a generator with state ON.
std::vector< HalfSpace_Rn::State > _GeneratorsState
The pair of generators state.
void dump(std::ostream &ofs)
Display the content on the stream passed as an argument.
unsigned int currentGenInNumber()
Iterator function.
std::vector< std::vector< unsigned int > > _HSPerNewGenerators
For each generator, store all raw pointers on their corresponding half-spaces.
std::vector< unsigned int > _GeneratorsInNumber
The generator numbers IN in a global list.
static std::string getStateAsText(const HalfSpace_Rn::State &)
void addGenerator(const std::vector< unsigned int > &commonFacets, unsigned int numbergenIN, unsigned int numbergenOUT, HalfSpace_Rn::State state)
Tell whether a pseudo neighbor is a genuine one comparing set of half-spaces.
Definition: Neighbours_Rn.h:69
unsigned int _iterator
A runner to iterate through the list of genuine neighbors.
std::vector< unsigned int > _GeneratorsOutNumber
The generator numbers OUT in a global list.