Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
qpong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Co
qpong
Commits
7692a38f
Commit
7692a38f
authored
Jan 26, 2020
by
Armin Co
Browse files
Options
Downloads
Patches
Plain Diff
Add Config.cpp to qpong lib.
parent
158d5aa7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/CMakeLists.txt
+1
-0
1 addition, 0 deletions
src/CMakeLists.txt
src/Config.cpp
+93
-7
93 additions, 7 deletions
src/Config.cpp
src/Config.hpp
+47
-36
47 additions, 36 deletions
src/Config.hpp
with
141 additions
and
43 deletions
src/CMakeLists.txt
+
1
−
0
View file @
7692a38f
...
@@ -4,6 +4,7 @@ add_library(qpong
...
@@ -4,6 +4,7 @@ add_library(qpong
ImageBuffer.cpp
ImageBuffer.cpp
QPlayer.cpp
QPlayer.cpp
Profiler.cpp
Profiler.cpp
Config.cpp
)
)
# @todo Check versions of glib etc. librarys.
# @todo Check versions of glib etc. librarys.
...
...
This diff is collapsed.
Click to expand it.
src/Config.cpp
+
93
−
7
View file @
7692a38f
...
@@ -8,27 +8,113 @@
...
@@ -8,27 +8,113 @@
#include
<iostream>
#include
<iostream>
#include
<fstream>
#include
<fstream>
Config
::
Config
(
std
::
string
filename
)
:
m_filename
{
filename
}
const
char
*
toStr
(
Setting
s
)
{
switch
(
s
)
{
case
Setting
::
ArrayHeight
:
return
"ArrayHeight"
;
break
;
case
Setting
::
ArrayWidth
:
return
"ArrayWidth"
;
break
;
case
Setting
::
MomentumX
:
return
"MomentumX"
;
break
;
case
Setting
::
MomentumY
:
return
"MomentumY"
;
break
;
case
Setting
::
PosX
:
return
"PosX"
;
break
;
case
Setting
::
PosY
:
return
"PosY"
;
break
;
case
Setting
::
None
:
return
"None"
;
break
;
}
}
Setting
fromStr
(
std
::
string
s
)
{
{
std
::
ifstream
file
(
m_filename
);
if
(
s
==
"ArrayWidth"
)
return
Setting
::
ArrayWidth
;
if
(
s
==
"ArrayHeight"
)
return
Setting
::
ArrayHeight
;
if
(
s
==
"MomentumX"
)
return
Setting
::
MomentumX
;
if
(
s
==
"MomentumY"
)
return
Setting
::
MomentumY
;
if
(
s
==
"PosX"
)
return
Setting
::
PosX
;
if
(
s
==
"PosY"
)
return
Setting
::
PosY
;
return
Setting
::
None
;
}
void
Config
::
saveTo
(
std
::
string
filename
)
{
}
void
Config
::
loadFrom
(
std
::
string
filename
)
{
std
::
cout
<<
"Loading form config"
<<
std
::
endl
;
{
std
::
ifstream
file
(
filename
);
while
(
file
)
{
std
::
string
line
;
std
::
getline
(
file
,
line
,
'\n'
);
std
::
cout
<<
line
<<
std
::
endl
;
}
file
.
close
();
}
s_filename
=
filename
;
std
::
ifstream
file
(
s_filename
);
while
(
file
)
while
(
file
)
{
{
std
::
string
key
;
std
::
string
key
;
std
::
getline
(
file
,
key
,
'
\n
'
);
std
::
getline
(
file
,
key
,
'
=
'
);
std
::
string
value
;
std
::
string
value
;
std
::
getline
(
file
,
value
,
'\n'
);
std
::
getline
(
file
,
value
,
'\n'
);
Setting
s
=
fromStr
(
key
);
Setting
s
=
fromStr
(
key
);
if
(
s
!=
Setting
::
None
)
if
(
s
!=
Setting
::
None
)
{
{
m_configs
[
s
]
=
value
;
setValue
(
s
,
value
);
std
::
cout
<<
"Key: "
<<
key
<<
std
::
endl
;
std
::
cout
<<
"Value: "
<<
value
<<
std
::
endl
;
}
}
else
else
{
{
std
::
cout
<<
"The setting
\"
"
<<
key
<<
"
\"
is unknown!"
<<
std
::
endl
;
std
::
cout
<<
"The setting
\"
"
<<
key
<<
"
\"
is unknown!"
<<
std
::
endl
;
break
;
}
}
}
}
void
Config
::
setValue
(
Setting
setting
,
std
::
string
value
)
{
switch
(
setting
)
{
case
Setting
::
ArrayWidth
:
{
unsigned
width
=
std
::
stoi
(
value
);
s_arrayWidth
=
width
;
break
;
}
case
Setting
::
ArrayHeight
:
{
int
height
=
std
::
stoi
(
value
);
s_arrayHeight
=
height
;
break
;
}
}
}
}
}
int
Config
::
getArrayWidth
(){
return
s_arrayWidth
;};
int
Config
::
getArrayHeight
(){
return
s_arrayHeight
;};
unsigned
Config
::
getArraySize
(){
return
Config
::
getArrayHeight
()
*
Config
::
getArrayWidth
();};
int
Config
::
getNumberOfThreads
(){
return
s_numberOfThreads
;};
double
Config
::
getHbar
(){
return
s_hBar
;};
double
Config
::
getInitialMomentumX
(){
return
s_initalMimentumX
;};
double
Config
::
getInitalMomentumY
(){
return
s_initialMomentumY
;};
double
Config
::
getInitialPosX
(){
return
s_initialPosX
;};
double
Config
::
getInitialPosY
(){
return
s_initialPosY
;};
double
Config
::
getInitialLambdaUnsharpness
(){
return
s_initialLambdaUnsharpness
;};
double
Config
::
getInitialValueScaleFactor
(){
return
s_initialValueScaleFactor
;};
double
Config
::
getBatScale
(){
return
s_batScale
;};
double
Config
::
getBatHeight
(){
return
s_batHeight
;};
double
Config
::
getBatCutOff
(){
return
s_batCatOff
;};
double
Config
::
getTimeStepSize
(){
return
s_timeStepSize
;};
double
Config
::
getFlattenMomentumCutOff
(){
return
s_flattenMomentumCutOff
;};
double
Config
::
getFlattenMomentumFallOff
(){
return
s_flattenMomentumFallOff
;};
double
Config
::
getMomentumImageScale
(){
return
s_momentumImageScale
;};
This diff is collapsed.
Click to expand it.
src/Config.hpp
+
47
−
36
View file @
7692a38f
...
@@ -27,57 +27,68 @@ enum class Setting
...
@@ -27,57 +27,68 @@ enum class Setting
};
};
const
char
*
toStr
(
Setting
setting
)
const
char
*
toStr
(
Setting
setting
);
{
switch
(
setting
)
Setting
fromStr
(
std
::
string
s
);
{
case
Setting
::
ArrayHeight
:
return
"ArrayHeight"
;
break
;
case
Setting
::
ArrayWidth
:
return
"ArrayWidth"
;
break
;
case
Setting
::
MomentumX
:
return
"MomentumX"
;
break
;
case
Setting
::
MomentumY
:
return
"MomentumY"
;
break
;
case
Setting
::
PosX
:
return
"PosX"
;
break
;
case
Setting
::
PosY
:
return
"PosY"
;
break
;
case
Setting
::
None
:
return
"None"
;
break
;
}
}
Setting
fromStr
(
std
::
string
s
)
{
if
(
s
==
"ArrayWidth"
)
return
Setting
::
ArrayWidth
;
if
(
s
==
"ArrayHeight"
)
return
Setting
::
ArrayHeight
;
if
(
s
==
"MomentumX"
)
return
Setting
::
MomentumX
;
if
(
s
==
"MomentumY"
)
return
Setting
::
MomentumY
;
if
(
s
==
"PosX"
)
return
Setting
::
PosX
;
if
(
s
==
"PosY"
)
return
Setting
::
PosY
;
return
Setting
::
None
;
}
class
Config
class
Config
{
{
public:
public:
Config
(
std
::
string
filename
);
static
void
loadFrom
(
std
::
string
s
);
void
loadFrom
(
std
::
string
filename
);
static
void
saveTo
(
std
::
string
s
);
void
saveTo
(
std
::
string
filename
);
static
void
setValue
(
Setting
setting
,
std
::
string
value
);
std
::
string
&
getFilename
();
static
std
::
string
&
getFilename
();
void
changeSetting
(
Setting
setting
,
std
::
string
&
value
);
static
int
getArrayWidth
();
static
int
getArrayHeight
();
static
unsigned
getArraySize
();
static
int
getNumberOfThreads
();
static
double
getHbar
();
static
double
getInitialMomentumX
();
static
double
getInitalMomentumY
();
static
double
getInitialPosX
();
static
double
getInitialPosY
();
static
double
getInitialLambdaUnsharpness
();
static
double
getInitialValueScaleFactor
();
std
::
string
&
getSetting
(
Setting
setting
);
static
double
getBatScale
();
static
double
getBatHeight
();
static
double
getBatCutOff
();
static
double
getTimeStepSize
();
static
double
getFlattenMomentumCutOff
();
static
double
getFlattenMomentumFallOff
();
static
double
getMomentumImageScale
();
private:
private:
std
::
string
m_filename
;
inline
static
std
::
string
s_filename
=
"qpong.config"
;
inline
static
unsigned
s_arrayWidth
=
384
;
inline
static
unsigned
s_arrayHeight
=
384
;
inline
static
unsigned
s_numberOfThreads
=
8
;
inline
static
double
s_hBar
=
0.0002
;
inline
static
double
s_initalMimentumX
=
0.063
;
inline
static
double
s_initialMomentumY
=
0.042
;
inline
static
double
s_initialPosX
=
0.0
;
inline
static
double
s_initialPosY
=
0.0
;
inline
static
double
s_initialLambdaUnsharpness
=
16.0
;
inline
static
double
s_initialValueScaleFactor
=
0.5
;
inline
static
double
s_batScale
=
0.000015
;
inline
static
double
s_batHeight
=
0.31
;
inline
static
double
s_batCatOff
=
0.0015
;
inline
static
double
s_timeStepSize
=
0.15
;
inline
static
double
s_flattenMomentumCutOff
=
0.012
;
inline
static
double
s_flattenMomentumFallOff
=
2.0
;
inline
static
double
s_momentumImageScale
=
55580.0
;
std
::
map
<
Setting
,
std
::
string
>
m_configs
;
};
};
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment