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
perception
imagine-planner
Commits
f441b825
Commit
f441b825
authored
Oct 02, 2017
by
Alejandro Suarez Hernandez
Browse files
substitution operators
parent
40fec844
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/examples/types_test.cpp
View file @
f441b825
...
...
@@ -214,6 +214,7 @@ BOOST_AUTO_TEST_CASE(substitution_test)
Predicate
p5
(
"q"
,
"Z"
);
Predicate
p6
(
"r"
);
Substitution
sigma
({{
"X"
,
TermWrapper
(
"a"
)},
{
"Y"
,
TermWrapper
(
"b"
)}});
Substitution
sigma_
({{
"W"
,
TermWrapper
(
"c"
)}});
INFO
(
"p1 = "
<<
p1
);
INFO
(
"p2 = "
<<
p2
);
INFO
(
"p3 = "
<<
p3
);
...
...
@@ -233,5 +234,13 @@ BOOST_AUTO_TEST_CASE(substitution_test)
BOOST_CHECK_EQUAL
(
p4_
.
to_str
(),
"q(b)"
);
BOOST_CHECK_EQUAL
(
p5_
.
to_str
(),
"q(Z)"
);
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
);
}
src/types.cpp
View file @
f441b825
...
...
@@ -231,6 +231,36 @@ void Substitution::remove(const std::string& 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
{
TermV
arguments
;
...
...
@@ -248,22 +278,44 @@ Predicate Substitution::operator()(const Predicate& predicate) const
PlanState
::
PlanState
()
{}
PlanState
::
PlanState
(
std
::
initializer_list
<
Predicate
>
il
)
:
predicates_
(
il
)
{}
// Implementation of StateQuery
PlanState
::
PlanState
(
const
std
::
set
<
Predicate
>&
predicates
)
:
predicates_
(
predicates
)
{}
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,
//const std::string& query) :
//state_(state), parameters_(parameters), values_(parameters),
//{
std
::
size_t
PlanState
::
hash
()
const
{
std
::
size_t
acc
=
0
;
for
(
const
Predicate
&
pred
:
predicates_
)
{
acc
+=
pred
.
hash
();
}
return
acc
;
}
//}
//bool StateQuery::next_solution()
//{
//return false;
//}
bool
PlanState
::
subset_of
(
const
PlanState
&
other
)
const
{
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
...
...
src/types.h
View file @
f441b825
...
...
@@ -261,6 +261,14 @@ class Substitution : public Stringifiable
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
;
int
size
()
const
{
return
sigma_
.
size
();
}
...
...
@@ -271,49 +279,54 @@ class Substitution : public Stringifiable
};
class
PlanState
class
PlanState
:
public
Stringifiable
,
public
Hashable
{
private:
typedef
std
::
set
<
Predicate
>
Container
;
Container
predicates_
;
std
::
set
<
Predicate
>
predicates_
;
public:
typedef
Container
::
const_iterator
CIter
;
typedef
std
::
set
<
Predicate
>
::
const_iterator
CIter
;
PlanState
();
PlanState
(
std
::
initializer_list
<
Predicate
>
il
);
template
<
typename
InputIterator
>
PlanState
(
InputIterator
begin
,
InputIterator
end
)
:
predicates_
(
begin
,
end
)
{}
CIter
begin
()
const
{
return
predicates_
.
begin
();
}
PlanState
(
const
std
::
set
<
Predicate
>&
predicates
);
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
//{
//private:
bool
subset_of
(
const
PlanState
&
other
)
const
;
//TermV parameters_, values_;
//std::string name_, pre_, post_;
bool
has
(
const
Predicate
&
predicate
)
const
{
return
(
bool
)
predicates_
.
count
(
predicate
);
}
//public:
void
put
(
const
Predicate
&
predicate
)
{
predicates_
.
insert
(
predicate
);
}
//Operator(TermV parameters_, const std::string& pre,
//const std::string& post);
void
remove
(
const
Predicate
&
predicate
)
{
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
...
...
Write
Preview
Supports
Markdown
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