Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imagine-planner
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perception
imagine-planner
Commits
f441b825
Commit
f441b825
authored
7 years ago
by
Alejandro Suarez Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
substitution operators
parent
40fec844
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/examples/types_test.cpp
+9
-0
9 additions, 0 deletions
src/examples/types_test.cpp
src/types.cpp
+64
-12
64 additions, 12 deletions
src/types.cpp
src/types.h
+38
-25
38 additions, 25 deletions
src/types.h
with
111 additions
and
37 deletions
src/examples/types_test.cpp
+
9
−
0
View file @
f441b825
...
@@ -214,6 +214,7 @@ BOOST_AUTO_TEST_CASE(substitution_test)
...
@@ -214,6 +214,7 @@ BOOST_AUTO_TEST_CASE(substitution_test)
Predicate
p5
(
"q"
,
"Z"
);
Predicate
p5
(
"q"
,
"Z"
);
Predicate
p6
(
"r"
);
Predicate
p6
(
"r"
);
Substitution
sigma
({{
"X"
,
TermWrapper
(
"a"
)},
{
"Y"
,
TermWrapper
(
"b"
)}});
Substitution
sigma
({{
"X"
,
TermWrapper
(
"a"
)},
{
"Y"
,
TermWrapper
(
"b"
)}});
Substitution
sigma_
({{
"W"
,
TermWrapper
(
"c"
)}});
INFO
(
"p1 = "
<<
p1
);
INFO
(
"p1 = "
<<
p1
);
INFO
(
"p2 = "
<<
p2
);
INFO
(
"p2 = "
<<
p2
);
INFO
(
"p3 = "
<<
p3
);
INFO
(
"p3 = "
<<
p3
);
...
@@ -233,5 +234,13 @@ BOOST_AUTO_TEST_CASE(substitution_test)
...
@@ -233,5 +234,13 @@ BOOST_AUTO_TEST_CASE(substitution_test)
BOOST_CHECK_EQUAL
(
p4_
.
to_str
(),
"q(b)"
);
BOOST_CHECK_EQUAL
(
p4_
.
to_str
(),
"q(b)"
);
BOOST_CHECK_EQUAL
(
p5_
.
to_str
(),
"q(Z)"
);
BOOST_CHECK_EQUAL
(
p5_
.
to_str
(),
"q(Z)"
);
BOOST_CHECK_EQUAL
(
p6_
.
to_str
(),
"r()"
);
BOOST_CHECK_EQUAL
(
p6_
.
to_str
(),
"r()"
);
Substitution
sigma_x
=
sigma
+
sigma_
;
BOOST_CHECK_EQUAL
(
sigma_x
.
to_str
(),
"{
\n
W -> c,
\n
X -> a,
\n
Y -> b
\n
}"
);
}
BOOST_AUTO_TEST_CASE
(
planstate_test
)
{
PlanState
state
({
Predicate
(
"p"
,
"x"
,
"y"
),
Predicate
(
"q"
,
"y"
),
Predicate
(
"r"
)});
INFO
(
state
);
}
}
This diff is collapsed.
Click to expand it.
src/types.cpp
+
64
−
12
View file @
f441b825
...
@@ -231,6 +231,36 @@ void Substitution::remove(const std::string& varname)
...
@@ -231,6 +231,36 @@ void Substitution::remove(const std::string& varname)
sigma_
.
erase
(
varname
);
sigma_
.
erase
(
varname
);
}
}
void
Substitution
::
operator
+=
(
const
Substitution
&
other
)
{
for
(
auto
entry
:
other
)
{
sigma_
.
insert
(
entry
);
}
}
void
Substitution
::
operator
-=
(
const
Substitution
&
other
)
{
for
(
auto
entry
:
other
)
{
sigma_
.
erase
(
entry
.
first
);
}
}
Substitution
Substitution
::
operator
+
(
const
Substitution
&
other
)
const
{
Substitution
ret
(
*
this
);
ret
+=
other
;
return
ret
;
}
Substitution
Substitution
::
operator
-
(
const
Substitution
&
other
)
const
{
Substitution
ret
;
ret
-=
other
;
return
ret
;
}
Predicate
Substitution
::
operator
()(
const
Predicate
&
predicate
)
const
Predicate
Substitution
::
operator
()(
const
Predicate
&
predicate
)
const
{
{
TermV
arguments
;
TermV
arguments
;
...
@@ -248,22 +278,44 @@ Predicate Substitution::operator()(const Predicate& predicate) const
...
@@ -248,22 +278,44 @@ Predicate Substitution::operator()(const Predicate& predicate) const
PlanState
::
PlanState
()
{}
PlanState
::
PlanState
()
{}
PlanState
::
PlanState
(
std
::
initializer_list
<
Predicate
>
il
)
:
predicates_
(
il
)
{}
PlanState
::
PlanState
(
const
std
::
set
<
Predicate
>&
predicates
)
:
predicates_
(
predicates
)
{}
// Implementation of StateQuery
std
::
string
PlanState
::
to_str
()
const
{
std
::
ostringstream
oss
;
bool
first
=
true
;
oss
<<
'{'
;
for
(
const
Predicate
&
pred
:
predicates_
)
{
if
(
not
first
)
oss
<<
','
;
oss
<<
pred
;
first
=
false
;
}
oss
<<
'}'
;
return
oss
.
str
();
}
//StateQuery::StateQuery(const PlanState& state, const TermV& parameters,
std
::
size_t
PlanState
::
hash
()
const
//const std::string& query) :
{
//state_(state), parameters_(parameters), values_(parameters),
std
::
size_t
acc
=
0
;
//{
for
(
const
Predicate
&
pred
:
predicates_
)
{
acc
+=
pred
.
hash
();
}
return
acc
;
}
//}
//bool StateQuery::next_solution()
bool
PlanState
::
subset_of
(
const
PlanState
&
other
)
const
//{
{
//return false;
if
(
predicates_
.
size
()
>
other
.
predicates_
.
size
())
return
false
;
//}
for
(
const
Predicate
&
pred
:
predicates_
)
{
if
(
not
other
.
has
(
pred
))
return
false
;
}
return
true
;
}
// Implementation of stream operator
// Implementation of stream operator
...
...
This diff is collapsed.
Click to expand it.
src/types.h
+
38
−
25
View file @
f441b825
...
@@ -261,6 +261,14 @@ class Substitution : public Stringifiable
...
@@ -261,6 +261,14 @@ class Substitution : public Stringifiable
void
remove
(
const
std
::
string
&
varname
);
void
remove
(
const
std
::
string
&
varname
);
void
operator
+=
(
const
Substitution
&
other
);
void
operator
-=
(
const
Substitution
&
other
);
Substitution
operator
+
(
const
Substitution
&
other
)
const
;
Substitution
operator
-
(
const
Substitution
&
other
)
const
;
Predicate
operator
()(
const
Predicate
&
predicate
)
const
;
Predicate
operator
()(
const
Predicate
&
predicate
)
const
;
int
size
()
const
{
return
sigma_
.
size
();
}
int
size
()
const
{
return
sigma_
.
size
();
}
...
@@ -271,49 +279,54 @@ class Substitution : public Stringifiable
...
@@ -271,49 +279,54 @@ class Substitution : public Stringifiable
};
};
class
PlanState
class
PlanState
:
public
Stringifiable
,
public
Hashable
{
{
private:
private:
typedef
std
::
set
<
Predicate
>
Container
;
std
::
set
<
Predicate
>
predicates_
;
Container
predicates_
;
public:
public:
typedef
Container
::
const_iterator
CIter
;
typedef
std
::
set
<
Predicate
>
::
const_iterator
CIter
;
PlanState
();
PlanState
();
PlanState
(
std
::
initializer_list
<
Predicate
>
il
);
PlanState
(
const
std
::
set
<
Predicate
>&
predicates
);
template
<
typename
InputIterator
>
PlanState
(
InputIterator
begin
,
InputIterator
end
)
:
predicates_
(
begin
,
end
)
{}
CIter
begin
()
const
{
return
predicates_
.
begin
();
}
CIter
end
()
const
{
return
predicates_
.
end
();
}
virtual
std
::
string
to_str
()
const
override
;
}
;
virtual
std
::
size_t
hash
()
const
override
;
bool
operator
==
(
const
PlanState
&
other
)
const
{
return
predicates_
==
other
.
predicates_
;
}
//class Operator
bool
subset_of
(
const
PlanState
&
other
)
const
;
//{
//private:
//TermV parameters_, values_;
bool
has
(
const
Predicate
&
predicate
)
const
//std::string name_, pre_, post_;
{
return
(
bool
)
predicates_
.
count
(
predicate
);
}
//public:
void
put
(
const
Predicate
&
predicate
)
{
predicates_
.
insert
(
predicate
);
}
//Operator(TermV parameters_, const std::string& pre,
void
remove
(
const
Predicate
&
predicate
)
//const std::string& post);
{
predicates_
.
erase
(
predicate
);
}
//bool is_ground() const;
template
<
typename
InputIterator
>
PlanState
(
InputIterator
begin
,
InputIterator
end
)
:
predicates_
(
begin
,
end
)
{}
//int arity
() const { return p
arame
te
r
s_.
size
(); }
CIter
begin
()
const
{
return
p
redica
tes_
.
begin
();
}
//};
CIter
end
()
const
{
return
predicates_
.
end
();
}
};
/**
/**
* @brief Stream operator that conveniently puts a Stringifiable object into
* @brief Stream operator that conveniently puts a Stringifiable object into
...
...
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