Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sergey Kireev
nle
Commits
c413a07d
Commit
c413a07d
authored
Mar 12, 2020
by
Sergey Kireev
Browse files
parameter enabling "optimization" added
parent
0a94f90c
Changes
4
Hide whitespace changes
Inline
Side-by-side
nle_cpp/src/main.cpp
View file @
c413a07d
...
...
@@ -66,34 +66,36 @@ int main(int argc,char *argv[]) {
const
int
nsize
=
p
.
get_nsize
();
if
(
p
.
is_hex
())
{
switch
(
nsize
)
{
case
1
:
{
NLE_hex_CA_optimized
<
1
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
1
>>
(
p
,
ca
);
}
break
;
case
2
:
{
NLE_hex_CA_optimized
<
2
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
2
>>
(
p
,
ca
);
}
break
;
case
3
:
{
NLE_hex_CA_optimized
<
3
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
3
>>
(
p
,
ca
);
}
break
;
case
4
:
{
NLE_hex_CA_optimized
<
4
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
4
>>
(
p
,
ca
);
}
break
;
case
5
:
{
NLE_hex_CA_optimized
<
5
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
5
>>
(
p
,
ca
);
}
break
;
case
6
:
{
NLE_hex_CA_optimized
<
6
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
6
>>
(
p
,
ca
);
}
break
;
case
7
:
{
NLE_hex_CA_optimized
<
7
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
7
>>
(
p
,
ca
);
}
break
;
case
8
:
{
NLE_hex_CA_optimized
<
8
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
8
>>
(
p
,
ca
);
}
break
;
case
9
:
{
NLE_hex_CA_optimized
<
9
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
9
>>
(
p
,
ca
);
}
break
;
case
10
:
{
NLE_hex_CA_optimized
<
10
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
10
>>
(
p
,
ca
);
}
break
;
default:
{
NLE_hex_CA
ca
(
nx
,
ny
,
nsize
);
count
<
NLE_hex_CA
>
(
p
,
ca
);
}
break
;
}
if
(
p
.
is_opt
()
&&
nsize
<=
10
)
switch
(
nsize
)
{
case
1
:
{
NLE_hex_CA_optimized
<
1
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
1
>>
(
p
,
ca
);
}
break
;
case
2
:
{
NLE_hex_CA_optimized
<
2
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
2
>>
(
p
,
ca
);
}
break
;
case
3
:
{
NLE_hex_CA_optimized
<
3
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
3
>>
(
p
,
ca
);
}
break
;
case
4
:
{
NLE_hex_CA_optimized
<
4
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
4
>>
(
p
,
ca
);
}
break
;
case
5
:
{
NLE_hex_CA_optimized
<
5
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
5
>>
(
p
,
ca
);
}
break
;
case
6
:
{
NLE_hex_CA_optimized
<
6
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
6
>>
(
p
,
ca
);
}
break
;
case
7
:
{
NLE_hex_CA_optimized
<
7
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
7
>>
(
p
,
ca
);
}
break
;
case
8
:
{
NLE_hex_CA_optimized
<
8
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
8
>>
(
p
,
ca
);
}
break
;
case
9
:
{
NLE_hex_CA_optimized
<
9
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
9
>>
(
p
,
ca
);
}
break
;
case
10
:
{
NLE_hex_CA_optimized
<
10
>
ca
(
nx
,
ny
);
count
<
NLE_hex_CA_optimized
<
10
>>
(
p
,
ca
);
}
break
;
}
else
{
NLE_hex_CA
ca
(
nx
,
ny
,
nsize
);
count
<
NLE_hex_CA
>
(
p
,
ca
);
}
}
else
{
switch
(
nsize
)
{
case
1
:
{
NLE_sqr_CA_optimized
<
1
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
1
>>
(
p
,
ca
);
}
break
;
case
2
:
{
NLE_sqr_CA_optimized
<
2
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
2
>>
(
p
,
ca
);
}
break
;
case
3
:
{
NLE_sqr_CA_optimized
<
3
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
3
>>
(
p
,
ca
);
}
break
;
case
4
:
{
NLE_sqr_CA_optimized
<
4
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
4
>>
(
p
,
ca
);
}
break
;
case
5
:
{
NLE_sqr_CA_optimized
<
5
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
5
>>
(
p
,
ca
);
}
break
;
case
6
:
{
NLE_sqr_CA_optimized
<
6
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
6
>>
(
p
,
ca
);
}
break
;
case
7
:
{
NLE_sqr_CA_optimized
<
7
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
7
>>
(
p
,
ca
);
}
break
;
case
8
:
{
NLE_sqr_CA_optimized
<
8
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
8
>>
(
p
,
ca
);
}
break
;
case
9
:
{
NLE_sqr_CA_optimized
<
9
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
9
>>
(
p
,
ca
);
}
break
;
case
10
:
{
NLE_sqr_CA_optimized
<
10
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
10
>>
(
p
,
ca
);
}
break
;
default:
{
NLE_sqr_CA
ca
(
nx
,
ny
,
nsize
);
count
<
NLE_sqr_CA
>
(
p
,
ca
);
}
break
;
}
if
(
p
.
is_opt
()
&&
nsize
<=
10
)
switch
(
nsize
)
{
case
1
:
{
NLE_sqr_CA_optimized
<
1
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
1
>>
(
p
,
ca
);
}
break
;
case
2
:
{
NLE_sqr_CA_optimized
<
2
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
2
>>
(
p
,
ca
);
}
break
;
case
3
:
{
NLE_sqr_CA_optimized
<
3
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
3
>>
(
p
,
ca
);
}
break
;
case
4
:
{
NLE_sqr_CA_optimized
<
4
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
4
>>
(
p
,
ca
);
}
break
;
case
5
:
{
NLE_sqr_CA_optimized
<
5
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
5
>>
(
p
,
ca
);
}
break
;
case
6
:
{
NLE_sqr_CA_optimized
<
6
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
6
>>
(
p
,
ca
);
}
break
;
case
7
:
{
NLE_sqr_CA_optimized
<
7
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
7
>>
(
p
,
ca
);
}
break
;
case
8
:
{
NLE_sqr_CA_optimized
<
8
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
8
>>
(
p
,
ca
);
}
break
;
case
9
:
{
NLE_sqr_CA_optimized
<
9
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
9
>>
(
p
,
ca
);
}
break
;
case
10
:
{
NLE_sqr_CA_optimized
<
10
>
ca
(
nx
,
ny
);
count
<
NLE_sqr_CA_optimized
<
10
>>
(
p
,
ca
);
}
break
;
}
else
{
NLE_sqr_CA
ca
(
nx
,
ny
,
nsize
);
count
<
NLE_sqr_CA
>
(
p
,
ca
);
}
}
return
0
;
...
...
nle_cpp/src/nle_ca.h
View file @
c413a07d
...
...
@@ -111,41 +111,3 @@ class NLE_hex_CA_optimized : public NLE_CA_base_optimized<hood_hex,nsize> {
////////////////////////////////////////////////////////////////////////////////////////////////////
class
NLE_CA
{
NLE_sqr_CA
*
sqrca
;
NLE_hex_CA
*
hexca
;
public:
const
int
nx
,
ny
;
NLE_CA
(
int
nx_
,
int
ny_
,
int
ns
,
ca2d
::
Neighborhood_type
hood_type
)
:
sqrca
(
nullptr
),
hexca
(
nullptr
),
nx
(
nx_
),
ny
(
ny_
)
{
if
(
hood_type
==
ca2d
::
hood_hex
)
hexca
=
new
NLE_hex_CA
(
nx
,
ny
,
ns
);
if
(
hood_type
==
ca2d
::
hood_vonNeumann
||
hood_type
==
ca2d
::
hood_default
)
sqrca
=
new
NLE_sqr_CA
(
nx
,
ny
,
ns
);
}
void
set_parameters
(
double
en_
,
double
el_
,
double
enl_
,
double
kT_
,
double
mu_
,
double
evap_
,
double
cond_
)
{
if
(
sqrca
!=
nullptr
)
{
sqrca
->
set_parameters
(
en_
,
el_
,
enl_
,
kT_
,
mu_
,
evap_
,
cond_
);
return
;
}
if
(
hexca
!=
nullptr
)
{
hexca
->
set_parameters
(
en_
,
el_
,
enl_
,
kT_
,
mu_
,
evap_
,
cond_
);
return
;
}
}
bool
load_binary
(
const
std
::
string
&
filename
)
{
if
(
sqrca
!=
nullptr
)
return
sqrca
->
load_binary
(
filename
);
if
(
hexca
!=
nullptr
)
return
hexca
->
load_binary
(
filename
);
return
false
;
}
void
save_binary
(
const
std
::
string
&
fn
,
int
it
=-
1
,
const
std
::
string
&
ext
=
""
)
const
{
if
(
sqrca
!=
nullptr
)
{
sqrca
->
save_binary
(
fn
,
it
,
ext
);
return
;
}
if
(
hexca
!=
nullptr
)
{
hexca
->
save_binary
(
fn
,
it
,
ext
);
return
;
}
}
void
fill
(
double
fracn
,
double
frace
)
{
if
(
sqrca
!=
nullptr
)
{
sqrca
->
fill
(
fracn
,
frace
);
return
;
}
if
(
hexca
!=
nullptr
)
{
hexca
->
fill
(
fracn
,
frace
);
return
;
}
}
std
::
map
<
int
,
int
>
count
()
const
{
if
(
sqrca
!=
nullptr
)
return
sqrca
->
count
();
if
(
hexca
!=
nullptr
)
return
hexca
->
count
();
return
std
::
map
<
int
,
int
>
();
}
void
iterate
()
{
if
(
sqrca
!=
nullptr
)
{
sqrca
->
iterate
();
return
;
}
if
(
hexca
!=
nullptr
)
{
hexca
->
iterate
();
return
;
}
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
nle_cpp/src/param.cpp
View file @
c413a07d
...
...
@@ -89,6 +89,10 @@
#define SQUHEX 4
#endif
#ifndef OPT
#define OPT 0
#endif
Parameters
::
Parameters
()
{
default_nx
=
NX
;
default_ny
=
NY
;
...
...
@@ -110,6 +114,7 @@ Parameters::Parameters() {
default_datafile_prefix
=
PREFIX
;
default_datafile_suffix
=
SUFFIX
;
default_squhex
=
SQUHEX
;
default_opt
=
OPT
;
reset
();
}
...
...
@@ -141,6 +146,8 @@ void Parameters::reset() {
squhex
=
default_squhex
;
opt
=
default_opt
;
//optimization_level = 0;
//check = false;
//half = false;
...
...
@@ -189,12 +196,17 @@ bool Parameters::read_from_cmdline(int argc,char *argv[]) {
std
::
cout
<<
" -ofs <string> - set output file suffix (default: "
<<
default_datafile_suffix
<<
")"
<<
std
::
endl
;
std
::
cout
<<
" -load <filename> - load data from file"
<<
std
::
endl
;
std
::
cout
<<
" -it <value> - set initial step value (default: 0)"
<<
std
::
endl
;
std
::
cout
<<
" -O - use nsize parameter optimization (default: "
<<
(
default_opt
?
"enabled"
:
"disabled"
)
<<
")"
<<
std
::
endl
;
std
::
cout
<<
" -long - set long output format (default: "
<<
(
default_long_output
?
"enabled"
:
"disabled"
)
<<
")"
<<
std
::
endl
;
std
::
cout
<<
" -short - set short output format (default: "
<<
(
default_long_output
?
"disabled"
:
"enabled"
)
<<
")"
<<
std
::
endl
;
//std::cout << " -O[<level>] - use optimized rule (0 - basic general rule, 1,2,3(default) - optimized rules)" << std::endl;
std
::
cout
<<
" -h - show this help"
<<
std
::
endl
;
return
false
;
}
else
if
(
strcmp
(
"-O"
,
argv
[
cnt
])
==
0
)
{
cnt
++
;
opt
=
1
;
}
else
if
(
strcmp
(
"-long"
,
argv
[
cnt
])
==
0
)
{
cnt
++
;
long_output
=
1
;
...
...
nle_cpp/src/param.h
View file @
c413a07d
...
...
@@ -11,6 +11,7 @@ class Parameters {
int
default_long_output
;
int
default_initial_step
;
int
default_squhex
;
int
default_opt
;
double
default_fraction_n
;
double
default_fraction_l
;
...
...
@@ -40,6 +41,7 @@ class Parameters {
int
long_output
;
int
initial_step
;
int
squhex
;
int
opt
;
std
::
string
datafile_prefix
;
std
::
string
datafile_suffix
;
...
...
@@ -91,5 +93,6 @@ public:
bool
is_square
()
const
{
return
squhex
==
4
;
}
bool
is_hex
()
const
{
return
squhex
==
6
;
}
bool
is_opt
()
const
{
return
opt
!=
0
;
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment