• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • Modifiers
ValueModifier.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright (C) 2011 Andreas Cord-Landwehr <cola@uni-paderborn.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "ValueModifier.h"
20 
21 #include <limits.h>
22 
23 #include "Pointer.h"
24 #include "Data.h"
25 
26 #include <QString>
27 #include <boost/random/mersenne_twister.hpp>
28 #include <boost/random/uniform_int.hpp>
29 #include <boost/random/uniform_real.hpp>
30 #include <boost/random/variate_generator.hpp>
31 
32 ValueModifier::ValueModifier()
33 {
34 }
35 
36 
37 template<typename T>
38 void ValueModifier::enumerate(const QList<T> &list, const QString &property, int start, const QString &baseString, bool overrideValues)
39 {
40  for (int i = 0; i < list.size(); i++) {
41  if (!overrideValues && !list[i]->property(property.toLatin1()).isNull()) {
42  return;
43  }
44  list[i]->setProperty(property.toLatin1(), baseString + QString::number(start++));
45  }
46 }
47 template ROCSLIB_EXPORT void ValueModifier::enumerate<DataPtr>(const QList<DataPtr> &list, const QString &property, int start, const QString &baseString, bool overrideValues);
48 template ROCSLIB_EXPORT void ValueModifier::enumerate<PointerPtr>(const QList<PointerPtr> &list, const QString &property, int start, const QString &baseString, bool overrideValues);
49 
50 
51 template<typename T>
52 void ValueModifier::enumerateAlpha(const QList< T >& list, const QString &property, const QString &start, bool overrideValues)
53 {
54  QString identifier = start;
55  for (int i = start.length()-1; i >= 0; --i) {
56  // ensure that we only have letters
57  if (!identifier.at(i).isLetter()) {
58  identifier.replace(i, 1, 'a');
59  }
60  }
61 
62  for (int i = 0; i < list.size(); i++) {
63  if (!overrideValues && !list[i]->property(property.toLatin1()).isNull()) {
64  return;
65  }
66  list[i]->setProperty(property.toLatin1(), identifier);
67  qDebug() << "XXX " << identifier;
68 
69  // compute new identifier by lexicographical increasing
70  for (int i = identifier.length()-1; i >= 0; --i) {
71  // ensure that we only have letters
72  if (identifier.at(i) != 'Z') {
73  identifier.replace(i, 1, QChar(identifier.at(i).toAscii() + 1));
74  break; // we are done, do not loop further
75  } else {
76  identifier.replace(i, 1, 'a');
77  }
78  if (i == 0 && identifier.at(0) == 'a') {
79  identifier.append('a');
80  }
81  }
82  }
83 }
84 template ROCSLIB_EXPORT void ValueModifier::enumerateAlpha<DataPtr>(const QList<DataPtr> &list, const QString &property, const QString &start, bool overrideValues);
85 template ROCSLIB_EXPORT void ValueModifier::enumerateAlpha<PointerPtr>(const QList<PointerPtr> &list, const QString &property, const QString &start, bool overrideValues);
86 
87 
88 template<typename T>
89 void ValueModifier::assignRandomIntegers(const QList<T> &list, const QString &property, int lowerLimit, int upperLimit, int seed, bool overrideValues)
90 {
91  if (lowerLimit > upperLimit) {
92  return;
93  }
94 
95  boost::mt19937 gen;
96  gen.seed(static_cast<unsigned int>(seed));
97 
98  boost::uniform_int<> distribution(lowerLimit, upperLimit);
99  boost::variate_generator<boost::mt19937&, boost::uniform_int<> > die(gen, distribution);
100 
101  for (int i = 0; i < list.size(); i++) {
102  if (!overrideValues && !list[i]->property(property.toLatin1()).isNull()) {
103  return;
104  }
105  list[i]->setProperty(property.toLatin1(), QString::number(die()));
106  }
107 }
108 template ROCSLIB_EXPORT void ValueModifier::assignRandomIntegers<DataPtr>(const QList<DataPtr> &list, const QString &property, int lowerLimit, int upperLimit, int seed, bool overrideValues);
109 template ROCSLIB_EXPORT void ValueModifier::assignRandomIntegers<PointerPtr>(const QList<PointerPtr> &list, const QString &property, int lowerLimit, int upperLimit, int seed, bool overrideValues);
110 
111 
112 template<typename T>
113 void ValueModifier::assignRandomReals(const QList<T> &list, const QString &property, qreal lowerLimit, qreal upperLimit, int seed, bool overrideValues)
114 {
115  if (lowerLimit > upperLimit) {
116  return;
117  }
118 
119  boost::mt19937 gen;
120  gen.seed(static_cast<unsigned int>(seed));
121 
122  boost::uniform_real<> distribution(lowerLimit, upperLimit);
123  boost::variate_generator<boost::mt19937&, boost::uniform_real<> > die(gen, distribution);
124 
125  for (int i = 0; i < list.size(); i++) {
126  if (!overrideValues && !list[i]->property(property.toLatin1()).isNull()) {
127  return;
128  }
129  list[i]->setProperty(property.toLatin1(), QString::number(die()));
130  }
131 }
132 template ROCSLIB_EXPORT void ValueModifier::assignRandomReals<DataPtr>(const QList<DataPtr> &list, const QString &property, qreal lowerLimit, qreal upperLimit, int seed, bool overrideValues);
133 template ROCSLIB_EXPORT void ValueModifier::assignRandomReals<PointerPtr>(const QList<PointerPtr> &list, const QString &property, qreal lowerLimit, qreal upperLimit, int seed, bool overrideValues);
134 
135 template<typename T>
136 void ValueModifier::assignConstantValue(const QList<T> &list, const QString &property, const QString &constant, bool overrideValues)
137 {
138  for (int i = 0; i < list.size(); i++) {
139  if (!overrideValues && !list[i]->property(property.toLatin1()).isNull()) {
140  return;
141  }
142  list[i]->setProperty(property.toLatin1(), constant);
143  }
144 }
145 template ROCSLIB_EXPORT void ValueModifier::assignConstantValue<DataPtr>(const QList<DataPtr> &list, const QString &property, const QString &constant, bool overrideValues);
146 template ROCSLIB_EXPORT void ValueModifier::assignConstantValue<PointerPtr>(const QList<PointerPtr> &list, const QString &property, const QString &constant, bool overrideValues);
ValueModifier::assignRandomReals
void assignRandomReals(const QList< T > &list, const QString &property, qreal lowerLimit, qreal upperLimit, int seed, bool overrideValues=true)
Assign float values uniformly at random from range [lowerLimit,upperLimit] to nodes.
Definition: ValueModifier.cpp:113
ValueModifier::enumerateAlpha
void enumerateAlpha(const QList< T > &list, const QString &property, const QString &start, bool overrideValues=true)
Assign strings in increasing order starting at 'start' to all nodes.
Definition: ValueModifier.cpp:52
ValueModifier::enumerate
void enumerate(const QList< T > &list, const QString &property, int start, const QString &baseString, bool overrideValues=true)
Assign integers in increasing order starting at 'start' to all nodes.
Definition: ValueModifier.cpp:38
ValueModifier::assignConstantValue
void assignConstantValue(const QList< T > &list, const QString &property, const QString &constant, bool overrideValues=true)
Assign a constant string value to nodes/pointers.
Definition: ValueModifier.cpp:136
Data.h
ValueModifier.h
ValueModifier::assignRandomIntegers
void assignRandomIntegers(const QList< T > &list, const QString &property, int lowerLimit, int upperLimit, int seed, bool overrideValues=true)
Assign integers uniformly at random from range [lowerLimit,upperLimit] to data elements.
Definition: ValueModifier.cpp:89
ROCSLIB_EXPORT
#define ROCSLIB_EXPORT
Definition: RocsCoreExport.h:32
Pointer.h
ValueModifier::ValueModifier
ValueModifier()
Definition: ValueModifier.cpp:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal