PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
real-time
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my alerts
my settings
my profile
Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free!
Click here to download the new Pastebin App for iOS
.
Public Pastes
Untitled
2 sec ago
Untitled
2 sec ago
Untitled
3 sec ago
Untitled
4 sec ago
Untitled
7 sec ago
Untitled
7 sec ago
Untitled
10 sec ago
Untitled
2 min ago
New Paste
#ifndef OB_PERMUTATION_H #define OB_PERMUTATION_H #include <map> #include <vector> #include <Eigen/Core> namespace OpenBabel { struct Permutation { /** * Default constructor. */ Permutation() {} /** * Constructor taking a @p map as argument. */ Permutation(const std::vector<unsigned int> &_map) : map(_map) {} /** * Constructor taking a @p matrix as argument. */ Permutation(const Eigen::MatrixXi &matrix) { setMatrix(matrix); } /** * Copy constructor. */ Permutation(const Permutation &other) { this->map = other.map; } /** * Print the permutation to std::cout in shortened notation. */ void print() const { std::vector<unsigned int>::const_iterator i; for (i = map.begin(); i != map.end(); ++i) std::cout << *i << " "; std::cout << std::endl; } Permutation apply(const Permutation &input) const { Permutation p; if (input.map.size() != map.size()) return p; p.map.resize(map.size()); unsigned int index = 0; std::vector<unsigned int>::const_iterator i; for (i = map.begin(); i != map.end(); ++i, ++index) { p.map[index] = input.map.at(*i-1); } return p; } /** * Compute the permutation matrix for this Permutation. */ Eigen::MatrixXi matrix() const { int n = map.size(); Eigen::MatrixXi P = Eigen::MatrixXi::Zero(n, n); for (int i = 0; i < n; ++i) { //P(map.at(i)-1, i) = 1; P(i, map.at(i)-1) = 1; } return P; } /** * Set the permutation matrix for this permutation. The matrix is * converted to a shortened notation permutation. */ void setMatrix(const Eigen::MatrixXi &m) { if (m.rows() != m.cols()) return; int size = m.rows(); map.resize(size); for (int i = 0; i < size; ++i) for (int j = 0; j < size; ++j) { if (m(i,j)) map[i] = j + 1; } } unsigned long NumInversions() const { std::vector<unsigned int> invVec; // the inversion vector std::vector<unsigned int>::const_iterator i, j; for (i = map.begin(); i != map.end(); ++i) { int e = 0; // ith element // loop over elements to the right for (j = i; j != map.end(); ++j) // increment e if element to the right is lower if (*j < *i) e++; invVec.push_back(e); } unsigned long sum = 0; for (std::vector<unsigned int>::iterator k = invVec.begin(); k != invVec.end(); ++k) sum += *k; return sum; } /** * Multiply two permutation matrices and return the resulting permutation. * This is the same as applying the two permutations consecutively. */ Permutation operator*(const Permutation &rhs) const { return apply(rhs); } /** * Equality operator. Two permutations are equal if their shortened notations * are the same (compared element-by-element). */ bool operator==(const Permutation &rhs) const { if (map.size() != rhs.map.size()) return false; std::vector<unsigned int>::const_iterator i1 = map.begin(); std::vector<unsigned int>::const_iterator i2 = rhs.map.begin(); for (; i1 != map.end(); ++i1, ++i2) if (*i1 != *i2) return false; return true; } std::vector<unsigned int> map; //!< The actual mapping in shortened notation }; struct PermutationGroup { /** * Default constructor. */ PermutationGroup() {} /** * Constructor taking vector of permutations as argument. */ PermutationGroup(const std::vector<Permutation> &_permutations) : permutations(_permutations) {} /** * @return The number of permutations in this group. */ unsigned int size() const { return permutations.size(); } /** * Add permutation @p p to this permutation group. */ void add(const Permutation &p) { permutations.push_back(p); //invIndexes.push_back(p.NumInversions()); } /** * @return A constant reference to the @p index-th permutation. */ const Permutation& at(unsigned int index) { return permutations.at(index); } /** * @return True if this permutation group contains permutation @p p. */ bool contains(const Permutation &p) const { //if (std::find(invIndexes.begin(), invIndexes.end(), p.NumInversions()) != invIndexes.end()) // return true; std::vector<Permutation>::const_iterator i; for (i = permutations.begin(); i != permutations.end(); ++i) if (*i == p) return true; return false; } std::vector<Permutation> permutations; //!< The actual permutations in the group //std::vector<unsigned long> invIndexes; //!< The inversion indexes }; } // namespace #endif
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
HTML 5
Java
JavaScript
Lua
None
Perl
PHP
Python
Rails
-------------
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
ActionScript
ActionScript 3
Ada
ALGOL 68
Apache Log
AppleScript
APT Sources
ASM (NASM)
ASP
autoconf
Autohotkey
AutoIt
Avisynth
Awk
BASCOM AVR
Bash
Basic4GL
BibTeX
Blitz Basic
BNF
BOO
BrainFuck
C
C for Macs
C Intermediate Language
C#
C++
C++ (with QT extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
ChaiScript
Clojure
Clone C
Clone C++
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
DCS
Delphi
Delphi Prism (Oxygene)
Diff
DIV
DOS
DOT
E
ECMAScript
Eiffel
Email
EPC
Erlang
F#
Falcon
FO Language
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
Game Maker
GDB
Genero
Genie
GetText
Go
Groovy
GwBasic
Haskell
HicEst
HQ9 Plus
HTML
HTML 5
Icon
IDL
INI file
Inno Script
INTERCAL
IO
J
Java
Java 5
JavaScript
jQuery
KiXtart
Latex
Liberty BASIC
Linden Scripting
Lisp
LLVM
Loco Basic
Logtalk
LOL Code
Lotus Formulas
Lotus Script
LScript
Lua
M68000 Assembler
MagikSF
Make
MapBasic
MatLab
mIRC
MIX Assembler
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MPASM
MXML
MySQL
newLISP
None
NullSoft Installer
Oberon 2
Objeck Programming Langua
Objective C
OCalm Brief
OCaml
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
Pascal
PAWN
PCRE
Per
Perl
Perl 6
PHP
PHP Brief
Pic 16
Pike
Pixel Bender
PL/SQL
PostgreSQL
POV-Ray
Power Shell
PowerBuilder
ProFTPd
Progress
Prolog
Properties
ProvideX
PureBasic
PyCon
Python
q/kdb+
QBasic
R
Rails
REBOL
REG
Robots
RPM Spec
Ruby
Ruby Gnuplot
SAS
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
SQL
SystemVerilog
T-SQL
TCL
Tera Term
thinBasic
TypoScript
Unicon
UnrealScript
Vala
VB.NET
VeriLog
VHDL
VIM
Visual Pro Log
VisualBasic
VisualFoxPro
WhiteSpace
WHOIS
Winbatch
XBasic
XML
Xorg Config
XPP
YAML
Z80 Assembler
ZXBasic
Paste Expiration:
Never
10 Minutes
1 Hour
1 Day
1 Month
Paste Exposure:
Public
Unlisted
Private (members only)
Paste Name / Title:
Hello
Guest
Sign Up
or
Login
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login