SlideShare a Scribd company logo
1 of 2
Download to read offline
tools.cpp
#include "tools.hpp"
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
void ProgressBar(int it, int num_iterations) {
std::cout << "r" << (double)it * 100 / num_iterations + 1 << "%" <<
std::flush;
}
std::string IntToString(int i) {
if (i < 0)
{
i = i*(-1);
}
int lenght = int(log(i+1)/log(10)+1);
char buffer[lenght];
sprintf(buffer, "%d", i);
return buffer;
}
bool BernoulliDistr(double P) {
double rnd = drand48();
if (rnd < P) return true;
else return false;
}
int Distance(int x1, int y1, int x2, int y2, int grid_size) {
int dx = fabs(x1 - x2);
if (dx > grid_size/2) dx = grid_size - dx;
int dy = fabs(y1 - y2);
if (dy > grid_size/2) dy = grid_size - dy;
return dx + dy;
}
double NormalDistr(double my, double sigma) {
double u = drand48();
double v = drand48();
double snormal = cos(2*3.141592654*u)*sqrt(-2*log(v));
return sigma*snormal+my;
}
double LogNormal(double ev, double var) {
double sigma = sqrt(log(var/(ev*ev) + 1));
double my = log(ev) - sigma*sigma / 2;
Seite 1
tools.cpp
return exp(NormalDistr(my, sigma));
}
Seite 2

More Related Content

What's hot (18)

D vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaD vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoya
 
week-5x
week-5xweek-5x
week-5x
 
เฉลยแบบฝึกหัดบทที่ 1
เฉลยแบบฝึกหัดบทที่ 1เฉลยแบบฝึกหัดบทที่ 1
เฉลยแบบฝึกหัดบทที่ 1
 
Sol10
Sol10Sol10
Sol10
 
Program of bar 3 d
Program of bar 3 dProgram of bar 3 d
Program of bar 3 d
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
1
11
1
 
Hotel Management In C++
Hotel Management In C++Hotel Management In C++
Hotel Management In C++
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
MFC Cosinus
MFC CosinusMFC Cosinus
MFC Cosinus
 
C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
 
Groovify your java code by hervé roussel
Groovify your java code by hervé rousselGroovify your java code by hervé roussel
Groovify your java code by hervé roussel
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
 

Viewers also liked

Could humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingCould humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingVorname Nachname
 
Electron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsElectron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsVorname Nachname
 
Structure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveStructure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveVorname Nachname
 
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Vorname Nachname
 
Smell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsSmell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsVorname Nachname
 

Viewers also liked (13)

Statistics.cpp
Statistics.cppStatistics.cpp
Statistics.cpp
 
Dpsm simu.hpp
Dpsm simu.hppDpsm simu.hpp
Dpsm simu.hpp
 
Could humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunnelingCould humans recognize odor by phonon assisted tunneling
Could humans recognize odor by phonon assisted tunneling
 
Dpsm simu.cpp
Dpsm simu.cppDpsm simu.cpp
Dpsm simu.cpp
 
Tools.hpp
Tools.hppTools.hpp
Tools.hpp
 
Electron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystemsElectron transport in one dimensional nanosystems
Electron transport in one dimensional nanosystems
 
Structure-odor relations: a modern perspective
Structure-odor relations: a modern perspectiveStructure-odor relations: a modern perspective
Structure-odor relations: a modern perspective
 
Statstockprog
StatstockprogStatstockprog
Statstockprog
 
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
Dynamical symmetry breaking in vibration-assisted transport through nanostruc...
 
Smell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrationsSmell in real noses: how the environment changes vibrations
Smell in real noses: how the environment changes vibrations
 
Statistics.hpp
Statistics.hppStatistics.hpp
Statistics.hpp
 
Main.cpp
Main.cppMain.cpp
Main.cpp
 
Econophysics
EconophysicsEconophysics
Econophysics
 

Similar to Tools.cpp (20)

Cpds lab
Cpds labCpds lab
Cpds lab
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
include.docx
include.docxinclude.docx
include.docx
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Lab Question
Lab QuestionLab Question
Lab Question
 
C basics
C basicsC basics
C basics
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C programming function
C  programming functionC  programming function
C programming function
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C questions
C questionsC questions
C questions
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 

More from Vorname Nachname (12)

Leni souza
Leni souzaLeni souza
Leni souza
 
Alien life forms
Alien life formsAlien life forms
Alien life forms
 
Spaceengine2
Spaceengine2Spaceengine2
Spaceengine2
 
Structural Language
Structural LanguageStructural Language
Structural Language
 
Language
LanguageLanguage
Language
 
Spaceengine2
Spaceengine2Spaceengine2
Spaceengine2
 
Spaceengine
SpaceengineSpaceengine
Spaceengine
 
Topology and Electrostatics
Topology and Electrostatics Topology and Electrostatics
Topology and Electrostatics
 
calculation of currents in nanowires
calculation of currents in nanowirescalculation of currents in nanowires
calculation of currents in nanowires
 
Summerpoject 2005
Summerpoject 2005Summerpoject 2005
Summerpoject 2005
 
Aspelmeyer
AspelmeyerAspelmeyer
Aspelmeyer
 
Arndt matter wave interferometry
Arndt matter wave interferometry Arndt matter wave interferometry
Arndt matter wave interferometry
 

Recently uploaded

SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxAleenaTreesaSaji
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRDelhi Call girls
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PPRINCE C P
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 

Recently uploaded (20)

SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptx
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
Engler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomyEngler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomy
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 

Tools.cpp

  • 1. tools.cpp #include "tools.hpp" #include <iostream> #include <fstream> #include <cmath> #include <cstdlib> void ProgressBar(int it, int num_iterations) { std::cout << "r" << (double)it * 100 / num_iterations + 1 << "%" << std::flush; } std::string IntToString(int i) { if (i < 0) { i = i*(-1); } int lenght = int(log(i+1)/log(10)+1); char buffer[lenght]; sprintf(buffer, "%d", i); return buffer; } bool BernoulliDistr(double P) { double rnd = drand48(); if (rnd < P) return true; else return false; } int Distance(int x1, int y1, int x2, int y2, int grid_size) { int dx = fabs(x1 - x2); if (dx > grid_size/2) dx = grid_size - dx; int dy = fabs(y1 - y2); if (dy > grid_size/2) dy = grid_size - dy; return dx + dy; } double NormalDistr(double my, double sigma) { double u = drand48(); double v = drand48(); double snormal = cos(2*3.141592654*u)*sqrt(-2*log(v)); return sigma*snormal+my; } double LogNormal(double ev, double var) { double sigma = sqrt(log(var/(ev*ev) + 1)); double my = log(ev) - sigma*sigma / 2; Seite 1