Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alta
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alta
alta
Commits
8ba2f0a2
Commit
8ba2f0a2
authored
Jan 29, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working Nd
parent
63c3f6be
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
56 additions
and
47 deletions
+56
-47
sources/core/args.h
sources/core/args.h
+3
-0
sources/core/common.h
sources/core/common.h
+1
-1
sources/core/data.h
sources/core/data.h
+1
-1
sources/core/function.h
sources/core/function.h
+2
-1
sources/plugins/rational_data/rational_data.cpp
sources/plugins/rational_data/rational_data.cpp
+8
-7
sources/plugins/rational_data/rational_data.h
sources/plugins/rational_data/rational_data.h
+1
-1
sources/plugins/rational_function/rational_function.cpp
sources/plugins/rational_function/rational_function.cpp
+16
-17
sources/plugins/rational_function/rational_function.h
sources/plugins/rational_function/rational_function.h
+2
-1
sources/plugins/rational_function/rational_function.pro
sources/plugins/rational_function/rational_function.pro
+3
-1
sources/tests/plugin_loader/main.cpp
sources/tests/plugin_loader/main.cpp
+19
-17
No files found.
sources/core/args.h
View file @
8ba2f0a2
...
@@ -10,6 +10,9 @@ class arguments
...
@@ -10,6 +10,9 @@ class arguments
public:
// functions
public:
// functions
// Constructor and destructor
// Constructor and destructor
arguments
()
{
}
;
arguments
(
int
argc
,
char
**
const
argv
)
arguments
(
int
argc
,
char
**
const
argv
)
{
{
std
::
string
key
;
std
::
string
key
;
...
...
sources/core/common.h
View file @
8ba2f0a2
...
@@ -9,7 +9,7 @@ class vec : public std::vector<double>
...
@@ -9,7 +9,7 @@ class vec : public std::vector<double>
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
vec
&
v
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
vec
&
v
)
{
{
for
(
int
i
=
0
;
i
<
v
.
size
();
++
i
)
for
(
unsigned
int
i
=
0
;
i
<
v
.
size
();
++
i
)
{
{
if
(
i
==
0
)
out
<<
"["
;
else
out
<<
", "
;
if
(
i
==
0
)
out
<<
"["
;
else
out
<<
", "
;
out
<<
v
[
i
]
;
out
<<
v
[
i
]
;
...
...
sources/core/data.h
View file @
8ba2f0a2
...
@@ -13,7 +13,7 @@ class data
...
@@ -13,7 +13,7 @@ class data
// Load data from a file
// Load data from a file
virtual
void
load
(
const
std
::
string
&
filename
)
=
0
;
virtual
void
load
(
const
std
::
string
&
filename
)
=
0
;
virtual
void
load
(
const
std
::
string
&
filename
,
double
min
,
double
max
)
=
0
;
virtual
void
load
(
const
std
::
string
&
filename
,
const
arguments
&
args
)
=
0
;
// Acces to data
// Acces to data
// virtual bool get(int i, double& x, double& y, double& t) const = 0 ;
// virtual bool get(int i, double& x, double& y, double& t) const = 0 ;
...
...
sources/core/function.h
View file @
8ba2f0a2
...
@@ -8,12 +8,13 @@
...
@@ -8,12 +8,13 @@
#include "common.h"
#include "common.h"
#include "args.h"
#include "args.h"
class
function
//: public std::function<double(double)>
class
function
{
{
public:
// methods
public:
// methods
// Overload the function operator
// Overload the function operator
virtual
vec
operator
()(
const
vec
&
x
)
const
=
0
;
virtual
vec
operator
()(
const
vec
&
x
)
const
=
0
;
virtual
vec
value
(
const
vec
&
x
)
const
=
0
;
// IO function to text files
// IO function to text files
virtual
void
load
(
const
std
::
string
&
filename
)
=
0
;
virtual
void
load
(
const
std
::
string
&
filename
)
=
0
;
...
...
sources/plugins/rational_data/rational_data.cpp
View file @
8ba2f0a2
...
@@ -10,11 +10,11 @@
...
@@ -10,11 +10,11 @@
void
rational_data
::
load
(
const
std
::
string
&
filename
)
void
rational_data
::
load
(
const
std
::
string
&
filename
)
{
{
load
(
filename
,
-
std
::
numeric_limits
<
double
>::
max
(),
std
::
numeric_limits
<
double
>::
max
())
;
arguments
args
;
load
(
filename
,
args
)
;
}
}
void
rational_data
::
load
(
const
std
::
string
&
filename
,
double
min
,
double
max
)
void
rational_data
::
load
(
const
std
::
string
&
filename
,
const
arguments
&
args
)
{
{
std
::
ifstream
file
(
filename
.
c_str
())
;
std
::
ifstream
file
(
filename
.
c_str
())
;
if
(
!
file
.
is_open
())
if
(
!
file
.
is_open
())
...
@@ -22,8 +22,9 @@ void rational_data::load(const std::string& filename, double min, double max)
...
@@ -22,8 +22,9 @@ void rational_data::load(const std::string& filename, double min, double max)
std
::
cerr
<<
"<<ERROR>> unable to open file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
std
::
cerr
<<
"<<ERROR>> unable to open file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
}
}
// N-Floats regexp
double
min
,
max
;
// boost::regex e ("^([0-9]*\.?[0-9]+[\\t ]?)");
min
=
args
.
get_float
(
"min"
,
-
std
::
numeric_limits
<
double
>::
max
())
;
max
=
args
.
get_float
(
"max"
,
std
::
numeric_limits
<
double
>::
max
())
;
_nX
=
0
;
_nY
=
0
;
_nX
=
0
;
_nY
=
0
;
std
::
vector
<
int
>
vs
;
int
current_vs
=
0
;
std
::
vector
<
int
>
vs
;
int
current_vs
=
0
;
...
@@ -102,8 +103,8 @@ void rational_data::load(const std::string& filename, double min, double max)
...
@@ -102,8 +103,8 @@ void rational_data::load(const std::string& filename, double min, double max)
{
{
// TODO Specify the delta in case
// TODO Specify the delta in case
// Handle multiple dim
// Handle multiple dim
v
[
dimX
()
+
dimY
()
+
i
]
=
v
[
dimX
()
+
i
]
-
0.01
;
v
[
dimX
()
+
dimY
()
+
i
]
=
v
[
dimX
()
+
i
]
-
args
.
get_float
(
"dt"
,
0.1
)
;
v
[
dimX
()
+
2
*
dimY
()
+
i
]
=
v
[
dimX
()
+
i
]
+
0.01
;
v
[
dimX
()
+
2
*
dimY
()
+
i
]
=
v
[
dimX
()
+
i
]
+
args
.
get_float
(
"dt"
,
0.1
)
;
}
}
}
}
...
...
sources/plugins/rational_data/rational_data.h
View file @
8ba2f0a2
...
@@ -20,7 +20,7 @@ class rational_data : public QObject, public data
...
@@ -20,7 +20,7 @@ class rational_data : public QObject, public data
// Load data from a file
// Load data from a file
virtual
void
load
(
const
std
::
string
&
filename
)
;
virtual
void
load
(
const
std
::
string
&
filename
)
;
virtual
void
load
(
const
std
::
string
&
filename
,
double
min
,
double
max
)
;
virtual
void
load
(
const
std
::
string
&
filename
,
const
arguments
&
args
)
;
// Acces to data
// Acces to data
virtual
bool
get
(
int
i
,
double
&
x
,
double
&
yl
,
double
&
yu
)
const
;
virtual
bool
get
(
int
i
,
double
&
x
,
double
&
yl
,
double
&
yu
)
const
;
...
...
sources/plugins/rational_function/rational_function.cpp
View file @
8ba2f0a2
...
@@ -23,28 +23,26 @@ rational_function::~rational_function()
...
@@ -23,28 +23,26 @@ rational_function::~rational_function()
}
}
// Overload the function operator
// Overload the function operator
vec
rational_function
::
operator
()
(
const
vec
&
x
)
const
vec
rational_function
::
value
(
const
vec
&
x
)
const
{
{
vec
res
;
vec
res
;
res
.
res
ize
(
dimY
()
)
;
res
.
res
erve
(
_nY
)
;
for
(
int
k
=
0
;
k
<
_nY
;
++
k
)
for
(
int
k
=
0
;
k
<
_nY
;
++
k
)
{
{
double
p
=
0.0
f
;
double
p
=
0.0
f
;
double
q
=
0.0
f
;
double
q
=
0.0
f
;
for
(
int
l
=
0
;
l
<
_nX
;
++
l
)
for
(
int
i
=
a
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
{
p
+=
a
[
i
]
*
this
->
p
(
x
,
i
)
;
}
for
(
int
i
=
a
.
size
()
-
1
;
i
>=
0
;
--
i
)
for
(
int
i
=
b
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
{
p
=
x
[
l
]
*
p
+
a
[
i
]
;
q
+=
b
[
i
]
*
this
->
q
(
x
,
i
)
;
}
for
(
int
i
=
b
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
q
=
x
[
l
]
*
q
+
b
[
i
]
;
}
}
}
res
[
k
]
=
p
/
q
;
res
[
k
]
=
p
/
q
;
}
}
return
res
;
return
res
;
...
@@ -133,16 +131,16 @@ void rational_function::save(const std::string& filename, const arguments& args)
...
@@ -133,16 +131,16 @@ void rational_function::save(const std::string& filename, const arguments& args)
std
::
ofstream
file
(
filename
.
c_str
(),
std
::
ios_base
::
trunc
);
std
::
ofstream
file
(
filename
.
c_str
(),
std
::
ios_base
::
trunc
);
for
(
double
x
=
min
[
0
];
x
<=
max
[
0
];
x
+=
dt
)
for
(
double
x
=
min
[
0
];
x
<=
max
[
0
];
x
+=
dt
)
{
{
vec
vx
;
vx
.
push_back
(
x
)
;
vec
vx
;
for
(
int
i
=
0
;
i
<
_nX
;
++
i
)
{
vx
.
push_back
(
x
)
;
}
file
<<
x
<<
"
\t
"
<<
((
*
this
)(
vx
)
)[
0
]
<<
std
::
endl
;
file
<<
x
<<
"
\t
"
<<
value
(
vx
)[
0
]
<<
std
::
endl
;
std
::
cout
<<
x
<<
"
\t
"
<<
((
*
this
)(
vx
)
)[
0
]
<<
std
::
endl
;
std
::
cout
<<
x
<<
"
\t
"
<<
value
(
vx
)[
0
]
<<
std
::
endl
;
}
}
}
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
rational_function
&
r
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
rational_function
&
r
)
{
{
std
::
cout
<<
"p = ["
;
std
::
cout
<<
"p = ["
;
for
(
int
i
=
0
;
i
<
r
.
a
.
size
();
++
i
)
for
(
unsigned
int
i
=
0
;
i
<
r
.
a
.
size
();
++
i
)
{
{
if
(
i
!=
0
)
if
(
i
!=
0
)
{
{
...
@@ -153,7 +151,7 @@ std::ostream& operator<< (std::ostream& out, const rational_function& r)
...
@@ -153,7 +151,7 @@ std::ostream& operator<< (std::ostream& out, const rational_function& r)
std
::
cout
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
"q = ["
;
std
::
cout
<<
"q = ["
;
for
(
int
i
=
0
;
i
<
r
.
b
.
size
();
++
i
)
for
(
unsigned
int
i
=
0
;
i
<
r
.
b
.
size
();
++
i
)
{
{
if
(
i
!=
0
)
if
(
i
!=
0
)
{
{
...
@@ -163,6 +161,7 @@ std::ostream& operator<< (std::ostream& out, const rational_function& r)
...
@@ -163,6 +161,7 @@ std::ostream& operator<< (std::ostream& out, const rational_function& r)
}
}
std
::
cout
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
"]"
<<
std
::
endl
;
return
out
;
}
}
...
...
sources/plugins/rational_function/rational_function.h
View file @
8ba2f0a2
...
@@ -24,7 +24,8 @@ class rational_function : public QObject, public function
...
@@ -24,7 +24,8 @@ class rational_function : public QObject, public function
virtual
~
rational_function
()
;
virtual
~
rational_function
()
;
// Overload the function operator
// Overload the function operator
virtual
vec
operator
()(
const
vec
&
x
)
const
;
virtual
vec
value
(
const
vec
&
x
)
const
;
virtual
vec
operator
()(
const
vec
&
x
)
const
{
return
value
(
x
)
;
}
;
// Get the p_i and q_j function
// Get the p_i and q_j function
virtual
double
p
(
const
vec
&
x
,
int
i
)
const
;
virtual
double
p
(
const
vec
&
x
,
int
i
)
const
;
...
...
sources/plugins/rational_function/rational_function.pro
View file @
8ba2f0a2
...
@@ -8,5 +8,7 @@ INCLUDEPATH += ../..
...
@@ -8,5 +8,7 @@ INCLUDEPATH += ../..
HEADERS
=
rational_function
.
h
HEADERS
=
rational_function
.
h
SOURCES
=
rational_function
.
cpp
SOURCES
=
rational_function
.
cpp
QMAKE_CXXFLAGS
+=
-
frounding
-
math
-
fPIC
QMAKE_CXXFLAGS
+=
-
frounding
-
math
\
-
fPIC
\
-
g
sources/tests/plugin_loader/main.cpp
View file @
8ba2f0a2
...
@@ -86,29 +86,31 @@ int main(int argc, char** argv)
...
@@ -86,29 +86,31 @@ int main(int argc, char** argv)
function
*
f
=
functions
[
0
]
;
function
*
f
=
functions
[
0
]
;
data
*
d
=
datas
[
0
]
;
data
*
d
=
datas
[
0
]
;
if
(
args
.
is_defined
(
"min"
)
&&
args
.
is_defined
(
"max"
))
d
->
load
(
args
[
"input"
],
args
);
{
d
->
load
(
args
[
"input"
],
args
.
get_float
(
"min"
,
0.0
f
),
args
.
get_float
(
"max"
,
1.0
f
));
}
else
if
(
args
.
is_defined
(
"min"
)
&&
!
args
.
is_defined
(
"max"
))
{
d
->
load
(
args
[
"input"
],
args
.
get_float
(
"min"
,
0.0
f
),
std
::
numeric_limits
<
double
>::
max
());
}
else
if
(
args
.
is_defined
(
"min"
)
&&
!
args
.
is_defined
(
"max"
))
{
d
->
load
(
args
[
"input"
],
-
std
::
numeric_limits
<
double
>::
max
(),
args
.
get_float
(
"min"
,
0.0
f
));
}
else
{
d
->
load
(
args
[
"input"
]);
}
bool
is_fitted
=
fitters
[
0
]
->
fit_data
(
d
,
f
)
;
bool
is_fitted
=
fitters
[
0
]
->
fit_data
(
d
,
f
)
;
// Display the result
// Display the result
if
(
is_fitted
)
if
(
is_fitted
)
{
{
functions
[
0
]
->
save
(
args
[
"output"
],
args
)
;
/*
vec min, max ;
min.assign(2, args.get_float("min", 0.0f)) ;
max.assign(2, args.get_float("max", 1.5f)) ;
int nb_samples = args.get_int("nb_samples", 100) ;
double dt = (max[0]-min[0]) / nb_samples ;
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
for(double x=min[0]; x<=max[0]; x+=dt)
{
vec vx ; for(int i=0;i<2; ++i) { vx.push_back(x) ; }
file << x << "\t" << f->value(vx)[0] << std::endl ;
std::cout << x << "\t" << f->value(vx)[0] << std::endl ;
}
/*/
f
->
save
(
args
[
"output"
],
args
)
;
//*/
}
}
else
else
{
{
...
...
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