Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CoMISo
CoMISo
Commits
d2815642
Commit
d2815642
authored
Mar 20, 2020
by
Robin Brost
Browse files
bug fixes
parent
6fa98ee5
Pipeline
#13841
failed with stages
in 3 minutes and 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Examples/small_exact_constraint_satifaction_example/main.cc
View file @
d2815642
...
...
@@ -93,10 +93,10 @@ public:
// Example main
int
main
(
void
)
{
std
::
cout
<<
"---------- 1) Get an instance of a problem..."
<<
std
::
endl
;
SmallNProblem
problem
;
//
std::cout << "---------- 1) Get an instance of a problem..." << std::endl;
//
SmallNProblem problem;
std
::
cout
<<
"---------- 2) Set up constraints..."
<<
std
::
endl
;
//
std::cout << "---------- 2) Set up constraints..." << std::endl;
/*
int n_constraints = 2; // there will be one constraints
...
...
@@ -147,31 +147,31 @@ int main(void)
*/
int
n_constraints
=
20
;
int
rows
=
n_constraints
;
int
cols
=
100
;
double
error
=
0.00000000001
;
//
int n_constraints = 20;
//
int rows = n_constraints;
//
int cols = 100;
//
double error = 0.00000000001;
std
::
vector
<
Eigen
::
Triplet
<
int
>>
triplets
;
Eigen
::
SparseMatrix
<
int
>
A
(
rows
,
cols
);
Eigen
::
VectorXd
x
(
cols
);
Eigen
::
VectorXi
b
(
rows
);
//
std::vector<Eigen::Triplet<int>> triplets;
//
Eigen::SparseMatrix<int> A(rows, cols);
//
Eigen::VectorXd x(cols);
//
Eigen::VectorXi b(rows);
//set triplets
triplets
.
clear
();
for
(
int
i
=
0
;
i
<
rows
;
i
++
){
if
(
i
==
0
){
triplets
.
push_back
({
i
,
0
,
1
});
triplets
.
push_back
({
i
,
(
cols
-
2
),
1
});
triplets
.
push_back
({
i
,
(
cols
-
1
),
-
1
});
}
else
{
triplets
.
push_back
({
i
,
0
,
1
});
triplets
.
push_back
({
i
,
i
,
1
});
triplets
.
push_back
({
i
,
(
i
+
1
),
-
1
});
}
}
A
.
setFromTriplets
(
triplets
.
begin
(),
triplets
.
end
());
//
triplets.clear();
//
for(int i = 0; i < rows; i++){
//
if(i == 0){
//
triplets.push_back({i, 0 , 1});
//
triplets.push_back({i, (cols - 2), 1});
//
triplets.push_back({i, (cols - 1), -1});
//
}else{
//
triplets.push_back({i, 0 , 1});
//
triplets.push_back({i, i , 1});
//
triplets.push_back({i, (i + 1), -1});
//
}
//
}
//
A.setFromTriplets(triplets.begin(), triplets.end());
//set x_vec 1,2,3,4...
...
...
@@ -181,7 +181,7 @@ int main(void)
//set b_vec = 0;
b
.
setZero
(
rows
);
//
b.setZero(rows);
/*
...
...
@@ -207,20 +207,20 @@ int main(void)
std::cout << "Constraint violation: " << (A.cast<double>() *x - b.cast<double>()).squaredNorm() << std::endl;
*/
std
::
cout
<<
"Constraint violation: "
<<
(
A
.
cast
<
double
>
()
*
x
-
b
.
cast
<
double
>
()).
squaredNorm
()
<<
std
::
endl
;
//
std::cout << "Constraint violation: " << (A.cast<double>() *x - b.cast<double>()).squaredNorm() << std::endl;
std
::
cout
<<
"---------- 6) Try to exactly fulfill constraints..."
<<
std
::
endl
;
//
std::cout << "---------- 6) Try to exactly fulfill constraints..." << std::endl;
ExactConstraintSatisfaction
satisfy
;
satisfy
.
print_matrix
(
A
);
satisfy
.
evaluation
(
A
,
b
,
x
);
//
ExactConstraintSatisfaction satisfy;
//
satisfy.print_matrix(A);
//
satisfy.evaluation(A, b, x);
std
::
cout
<<
"values of vector x : "
<<
x
<<
std
::
endl
;
//
std::cout << "values of vector x : " << x << std::endl;
std
::
cout
<<
"---------- 7) Check constraint violation again..."
<<
std
::
endl
;
//
std::cout << "---------- 7) Check constraint violation again..." << std::endl;
std
::
cout
<<
"Constraint violation: "
<<
(
A
.
cast
<
double
>
()
*
x
-
b
.
cast
<
double
>
()).
squaredNorm
()
<<
std
::
endl
;
//
std::cout << "Constraint violation: " << (A.cast<double>() *x - b.cast<double>()).squaredNorm() << std::endl;
return
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