Jpp  15.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
JCOMPASS::JPolicy Struct Reference

Auxiliary class to define policy for invalid modules. More...

#include <JPolicy.hh>

Inheritance diagram for JCOMPASS::JPolicy:
std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t >

Public Member Functions

template<class T >
 JPolicy (const JModuleRouter &router, T __begin, T __end, const size_t size=1)
 Constructor. More...
 

Detailed Description

Auxiliary class to define policy for invalid modules.

The policy is defined as a map of the identifier of a module to a list of identifiers of valid modules.
For invalid modules, the valid modules in the nearest floors in the same string are selected.

Definition at line 31 of file JPolicy.hh.

Constructor & Destructor Documentation

template<class T >
JCOMPASS::JPolicy::JPolicy ( const JModuleRouter router,
T  __begin,
T  __end,
const size_t  size = 1 
)
inline

Constructor.

Parameters
routermodule router
__beginbegin of list with identifiers of valid modules
__endend of list with identifiers of valid modules
sizeminimum number of valid modules in case of an invalid module

Definition at line 44 of file JPolicy.hh.

45  {
46  using namespace std;
47  using namespace JPP;
48 
49  map<int, set<int> > zmap; // valid modules per string
50 
51  for (T i = __begin; i != __end; ++i) {
52 
53  if (router.hasModule(*i)) {
54 
55  const JLocation& location = router.getModule(*i);
56 
57  zmap[location.getString()].insert(location.getFloor());
58  }
59  }
60 
61  map<JLocation, int> detector; // inverse router
62 
63  for (JModuleRouter::const_iterator module = router->begin(); module != router->end(); ++module) {
64  detector[module->getLocation()] = module->getID();
65  }
66 
67  for (JModuleRouter::const_iterator module = router->begin(); module != router->end(); ++module) {
68 
69  if (module->getFloor() != 0) {
70 
71  const int id = module->getID();
72  const int string = module->getString();
73 
74  if (!zmap[string].empty()) {
75 
76  if (zmap[string].count(module->getFloor()) != 0) {
77 
78  (*this)[id].push_back(id);
79 
80  } else {
81 
82  for (size_t step = 1; step < zmap[string].size() && (*this)[id].size() < size; ++step) {
83  for (int sign : { -1, +1 }) {
84 
85  const int floor = module->getFloor() + sign * step;
86 
87  if (zmap[string].count(floor) != 0) {
88  (*this)[id].push_back(detector[JLocation(string,floor)]);
89  }
90  }
91  }
92  }
93  }
94  }
95  }
96  }
JDetector::const_iterator const_iterator
do set_variable OUTPUT_DIRECTORY $WORKDIR T
std::vector< int > count
Definition: JAlgorithm.hh:180
int sign(const T &value)
Get sign of value.
Definition: JLib.hh:20
do set_variable DETECTOR_TXT $WORKDIR detector

The documentation for this struct was generated from the following file: