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
a784f96c
Commit
a784f96c
authored
Apr 04, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring the plugin manager and rational function calls.
parent
f1cd2122
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
119 additions
and
62 deletions
+119
-62
sources/core/args.h
sources/core/args.h
+3
-1
sources/core/common.h
sources/core/common.h
+17
-7
sources/core/plugins_manager.cpp
sources/core/plugins_manager.cpp
+39
-11
sources/core/plugins_manager.h
sources/core/plugins_manager.h
+1
-1
sources/core/rational_function.cpp
sources/core/rational_function.cpp
+4
-0
sources/core/rational_function.h
sources/core/rational_function.h
+1
-0
sources/plugins/rational_fitter_parallel/quadratic_program.h
sources/plugins/rational_fitter_parallel/quadratic_program.h
+1
-1
sources/plugins/rational_fitter_parallel/rational_fitter.cpp
sources/plugins/rational_fitter_parallel/rational_fitter.cpp
+50
-25
sources/plugins/rational_fitter_parallel/rational_fitter.h
sources/plugins/rational_fitter_parallel/rational_fitter.h
+0
-4
sources/softs/plugin_loader/main.cpp
sources/softs/plugin_loader/main.cpp
+3
-12
No files found.
sources/core/args.h
View file @
a784f96c
...
...
@@ -9,6 +9,8 @@
/*! \brief A useful class for storing the high-level arguments of a program
* or a function.
* \ingroup core
* \internal
*
* The set of parameters are parsed from the command line using the
* constructor. They are stored as std::string in a std::map.
...
...
@@ -75,7 +77,7 @@ class arguments
}
else
{
std
::
cerr
<<
"Underfined request to key :
\"
"
<<
key
<<
"
\"
"
<<
std
::
endl
;
//
std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ;
return
std
::
string
()
;
}
}
;
...
...
sources/core/common.h
View file @
a784f96c
...
...
@@ -5,12 +5,14 @@
#include <cassert>
#include <cmath>
/*! \brief A core implementation of a vector of double.
/*! \brief A core implementation of a vector of double.
* \ingroup core
* \internal
*
* \details
*
This type is used for any transmission of vector data with unfixed
*
dimension. It allows to have a generic fitter working for
* n-Dimensional data.
*
\details
*
This type is used for any transmission of vector data with unfixed
*
dimension. It allows to have a generic fitter working for
*
n-Dimensional data.
*/
class
vec
:
public
std
::
vector
<
double
>
{
...
...
@@ -23,13 +25,21 @@ class vec : public std::vector<double>
vec
(
int
dim
)
:
std
::
vector
<
double
>
(
dim
)
{
assign
(
dim
,
0.0
)
;
}
;
}
virtual
~
vec
()
{
}
;
}
// Mathematical operators
//
vec
operator
=
(
const
vec
&
a
)
{
for
(
unsigned
int
i
=
0
;
i
<
this
->
size
();
++
i
)
{
this
->
at
(
i
)
=
a
[
i
];
}
return
*
this
;
}
friend
vec
operator
-
(
const
vec
&
a
)
{
vec
b
(
a
.
size
())
;
...
...
sources/core/plugins_manager.cpp
View file @
a784f96c
...
...
@@ -144,6 +144,14 @@ fitter* plugins_manager::get_fitter() const
//
function
*
plugins_manager
::
get_function
(
const
std
::
string
&
n
)
{
if
(
n
.
empty
())
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> no function plugin specified, returning a rational function"
<<
std
::
endl
;
#endif
return
new
rational_function
();
}
#ifdef USING_STATIC
FunctionPrototype
myFunction
=
(
FunctionPrototype
)
QLibrary
::
resolve
(
QString
(
n
.
c_str
()),
"_Z16provide_functionv"
);
...
...
@@ -171,22 +179,42 @@ function* plugins_manager::get_function(const std::string& n)
}
#endif
}
data
*
plugins_manager
::
get_data
(
const
std
::
string
&
n
)
const
data
*
plugins_manager
::
get_data
(
const
std
::
string
&
n
)
{
if
(
_datas
.
count
(
n
)
==
0
)
{
if
(
n
.
empty
()
)
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> using vertical segment data loader"
<<
std
::
endl
;
std
::
cout
<<
"<<DEBUG>> no data plugin specified, returning a vertial_segment loader"
<<
std
::
endl
;
#endif
return
new
vertical_segment
()
;
}
else
{
return
new
vertical_segment
();
}
#ifdef USING_STATIC
DataPrototype
myData
=
(
DataPrototype
)
QLibrary
::
resolve
(
QString
(
n
.
c_str
()),
"_Z16provide_datav"
);
if
(
myData
!=
NULL
)
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> using
\"
"
<<
n
<<
"
\"
data loader"
<<
std
::
endl
;
std
::
cout
<<
"<<DEBUG>> using function provider in file
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
#endif
return
myData
();
}
else
{
std
::
cerr
<<
"<<ERROR>> no data provider found in file
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
return
new
vertical_segment
()
;
}
#else
if
(
_functions
.
count
(
n
)
==
0
)
{
return
new
vertical_segment
()
;
}
else
{
return
_datas
.
find
(
n
)
->
second
;
}
#endif
return
_datas
.
find
(
n
)
->
second
;
}
}
fitter
*
plugins_manager
::
get_fitter
(
const
std
::
string
&
n
)
const
{
...
...
sources/core/plugins_manager.h
View file @
a784f96c
...
...
@@ -32,7 +32,7 @@ class plugins_manager
//! \brief Get instances of the function, the data and the fitter, select one
//! based on the name. Return null if no one exist.
static
function
*
get_function
(
const
std
::
string
&
n
)
;
data
*
get_data
(
const
std
::
string
&
n
)
const
;
static
data
*
get_data
(
const
std
::
string
&
n
)
;
fitter
*
get_fitter
(
const
std
::
string
&
n
)
const
;
//! \brief Provide a measure of how much memory there is on the system.
...
...
sources/core/rational_function.cpp
View file @
a784f96c
...
...
@@ -13,6 +13,10 @@ rational_function::rational_function() : a(), b()
{
}
rational_function
::
rational_function
(
int
np
,
int
nq
)
:
a
(
np
),
b
(
nq
)
{
}
rational_function
::
rational_function
(
const
std
::
vector
<
double
>&
a
,
const
std
::
vector
<
double
>&
b
)
:
a
(
a
),
b
(
b
)
...
...
sources/core/rational_function.h
View file @
a784f96c
...
...
@@ -20,6 +20,7 @@ class rational_function : public QObject, public function
public:
// methods
rational_function
()
;
rational_function
(
int
np
,
int
nq
)
;
rational_function
(
const
std
::
vector
<
double
>&
a
,
const
std
::
vector
<
double
>&
b
)
;
virtual
~
rational_function
()
;
...
...
sources/plugins/rational_fitter_parallel/quadratic_program.h
View file @
a784f96c
...
...
@@ -72,7 +72,7 @@ public:
{
return
CI
.
ncols
();
}
//! \brief Solves the quadratic program and update the p and
//! q vector if necessary.
inline
bool
solve_program
(
QuadProgPP
::
Vector
<
double
>&
x
,
double
&
delta
,
vec
&
p
,
vec
&
q
)
...
...
sources/plugins/rational_fitter_parallel/rational_fitter.cpp
View file @
a784f96c
...
...
@@ -52,6 +52,8 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit, const ar
r
->
setMin
(
d
->
min
())
;
r
->
setMax
(
d
->
max
())
;
const
int
_min_np
=
args
.
get_int
(
"min-np"
,
10
);
const
int
_max_np
=
args
.
get_int
(
"np"
,
_min_np
);
std
::
cout
<<
"<<INFO>> N in ["
<<
_min_np
<<
", "
<<
_max_np
<<
"]"
<<
std
::
endl
;
for
(
int
i
=
_min_np
;
i
<=
_max_np
;
++
i
)
...
...
@@ -81,6 +83,24 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit, const ar
std
::
cout
<<
"<<DEBUG>> will use "
<<
nb_cores
<<
" threads to compute the quadratic programs"
<<
std
::
endl
;
#endif
omp_set_num_threads
(
nb_cores
)
;
std
::
vector
<
rational_function
*>
rs
;
for
(
int
j
=
0
;
j
<
nb_cores
;
++
j
)
{
rational_function
*
rj
=
dynamic_cast
<
rational_function
*>
(
plugins_manager
::
get_function
(
args
[
"func"
]));
rj
->
setDimX
(
d
->
dimX
())
;
rj
->
setDimY
(
d
->
dimY
())
;
rj
->
setMin
(
d
->
min
())
;
rj
->
setMax
(
d
->
max
())
;
if
(
rj
==
NULL
)
{
std
::
cerr
<<
"<<ERROR>> unable to obtain a rational function from the plugins manager"
<<
std
::
endl
;
return
false
;
}
rs
.
push_back
(
rj
);
}
double
min_delta
=
std
::
numeric_limits
<
double
>::
max
();
int
nb_sol_found
=
0
;
...
...
@@ -95,7 +115,7 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit, const ar
vec
p
(
temp_np
*
r
->
dimY
()),
q
(
temp_nq
*
r
->
dimY
());
double
delta
;
bool
is_fitted
=
fit_data
(
d
,
temp_np
,
temp_nq
,
r
,
p
,
q
,
delta
);
bool
is_fitted
=
fit_data
(
d
,
temp_np
,
temp_nq
,
rs
[
omp_get_thread_num
()]
,
p
,
q
,
delta
);
if
(
is_fitted
)
{
#pragma omp critical
...
...
@@ -116,6 +136,12 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit, const ar
}
}
// Clean memory
for
(
int
j
=
0
;
j
<
nb_cores
;
++
j
)
{
delete
rs
[
j
];
}
if
(
min_delta
<
std
::
numeric_limits
<
double
>::
max
())
{
int
msec
=
time
.
elapsed
()
;
...
...
@@ -135,10 +161,6 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit, const ar
void
rational_fitter_parallel
::
set_parameters
(
const
arguments
&
args
)
{
_max_np
=
args
.
get_float
(
"np"
,
10
)
;
_max_nq
=
args
.
get_float
(
"nq"
,
10
)
;
_min_np
=
args
.
get_float
(
"min-np"
,
_max_np
)
;
_min_nq
=
args
.
get_float
(
"min-nq"
,
_max_nq
)
;
}
...
...
@@ -182,21 +204,20 @@ bool rational_fitter_parallel::fit_data(const vertical_segment* dat, int np, int
quadratic_program
qp
(
np
,
nq
);
#ifndef TODO_PUT_IN_METHOD
for
(
int
i
=
0
;
i
<
d
->
size
()
/
10
;
++
i
)
for
(
int
i
=
0
;
i
<
d
->
size
();
++
i
)
{
// Create two vector of constraints
vec
c1
(
n
),
c2
(
n
);
get_constraint
(
10
*
i
,
np
,
nq
,
ny
,
d
,
r
,
c1
,
c2
);
get_constraint
(
i
,
np
,
nq
,
ny
,
d
,
r
,
c1
,
c2
);
qp
.
add_constraints
(
c1
);
qp
.
add_constraints
(
c2
);
}
#endif
do
while
(
true
)
{
QuadProgPP
::
Vector
<
double
>
x
(
n
);
bool
solves_qp
=
qp
.
solve_program
(
x
,
delta
,
p
,
q
);
...
...
@@ -205,30 +226,34 @@ bool rational_fitter_parallel::fit_data(const vertical_segment* dat, int np, int
#ifdef DEBUG
std
::
cout
<<
"<<INFO>> got solution "
<<
*
r
<<
std
::
endl
;
#endif
return
true
;
}
/*
int current = 0, i=0;
while(i < 100 && current < m)
{
int current = 0, i=0;
while(i < 100 && current < m)
{
int next = quadratic_program::next_unmatching_constraint(current, ny, );
int next = quadratic_program::next_unmatching_constraint(current, ny, );
// Create two vector of constraints
vec c1(n), c2(n);
get_constraint(next, np, nq, ny, d, r, c1, c2);
// Create two vector of constraints
vec c1(n), c2(n);
get_constraint(next, np, nq, ny, d, r, c1, c2);
qp.add_constraints(c1);
qp.add_constraints(c2);
qp.add_constraints(c1);
qp.add_constraints(c2);
++i;
current = next;
}
++i;
current = next;
}
*/
return
true
;
}
else
{
return
false
;
}
}
while
(
qp
.
nb_constraints
()
<
2
*
m
);
return
false
;
std
::
cerr
<<
"<<ERROR>> should not atteign this part of the code"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
return
false
;
}
void
rational_fitter_parallel
::
get_constraint
(
int
i
,
int
np
,
int
nq
,
int
ny
,
...
...
sources/plugins/rational_fitter_parallel/rational_fitter.h
View file @
a784f96c
...
...
@@ -53,9 +53,5 @@ class rational_fitter_parallel : public QObject, public fitter
//! \brief Create a constraint vector given its index i in the data
// object and the rational function object to fit.
virtual
void
get_constraint
(
int
i
,
int
np
,
int
nq
,
int
ny
,
const
vertical_segment
*
data
,
const
rational_function
*
func
,
vec
&
cu
,
vec
&
cl
);
// min and Max usable np and nq values for the fitting
int
_max_np
,
_max_nq
;
int
_min_np
,
_min_nq
;
}
;
sources/softs/plugin_loader/main.cpp
View file @
a784f96c
...
...
@@ -44,22 +44,13 @@ int main(int argc, char** argv)
// if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
{
fit
->
set_parameters
(
args
)
;
function
*
f
=
NULL
;
if
(
args
.
is_defined
(
"func"
))
{
std
::
cout
<<
"<<INFO>> Using plugin function
\"
"
<<
args
[
"func"
]
<<
"
\"
"
<<
std
::
endl
;
f
=
manager
.
get_function
(
args
[
"func"
])
;
}
else
{
f
=
fit
->
provide_function
()
;
}
data
*
d
=
fit
->
provide_data
()
;
function
*
f
=
plugins_manager
::
get_function
(
args
[
"func"
]);
data
*
d
=
plugins_manager
::
get_data
(
args
[
"data"
]);
d
->
load
(
args
[
"input"
],
args
);
QTime
time
;
time
.
start
()
;
bool
is_fitted
=
fit
->
fit_data
(
d
,
f
)
;
bool
is_fitted
=
fit
->
fit_data
(
d
,
f
,
args
)
;
int
msec
=
time
.
elapsed
()
;
int
sec
=
(
msec
/
1000
)
%
60
;
int
min
=
(
msec
/
60000
)
%
60
;
...
...
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