Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon
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
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
Franck Dary
macaon
Commits
85c149fc
Commit
85c149fc
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added the oracle to compute the cost of a transition on a config into the class Transition
parent
db30ed5b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
reading_machine/include/Transition.hpp
+6
-0
6 additions, 0 deletions
reading_machine/include/Transition.hpp
reading_machine/src/Transition.cpp
+36
-8
36 additions, 8 deletions
reading_machine/src/Transition.cpp
with
42 additions
and
8 deletions
reading_machine/include/Transition.hpp
+
6
−
0
View file @
85c149fc
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
<vector>
#include
<vector>
#include
"Action.hpp"
#include
"Action.hpp"
#include
"Config.hpp"
class
Transition
class
Transition
{
{
...
@@ -10,6 +11,11 @@ class Transition
...
@@ -10,6 +11,11 @@ class Transition
std
::
string
name
;
std
::
string
name
;
std
::
vector
<
Action
>
sequence
;
std
::
vector
<
Action
>
sequence
;
std
::
function
<
int
(
const
Config
&
config
)
>
cost
;
private
:
void
initWrite
(
std
::
string
colName
,
std
::
string
object
,
std
::
string
index
,
std
::
string
value
);
public
:
public
:
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Transition.cpp
+
36
−
8
View file @
85c149fc
...
@@ -7,21 +7,49 @@ Transition::Transition(const std::string & name)
...
@@ -7,21 +7,49 @@ Transition::Transition(const std::string & name)
std
::
regex
writeRegex
(
"WRITE ([bs])
\\
.(.+) (.+) (.+)"
);
std
::
regex
writeRegex
(
"WRITE ([bs])
\\
.(.+) (.+) (.+)"
);
std
::
smatch
sm
;
auto
doIfNameMatch
=
[
name
](
auto
&
reg
,
auto
init
)
{
std
::
smatch
sm
;
std
::
regex_match
(
name
,
sm
,
reg
);
if
(
sm
.
empty
())
return
false
;
init
(
sm
);
return
true
;
};
try
try
{
{
std
::
regex_match
(
name
,
sm
,
writeRegex
);
if
(
doIfNameMatch
(
writeRegex
,
[
this
](
auto
sm
){
initWrite
(
sm
[
3
],
sm
[
1
],
sm
[
2
],
sm
[
4
]);}))
if
(
!
sm
.
empty
())
{
sequence
.
emplace_back
(
Action
::
addHypothesisRelative
(
sm
[
3
],
Action
::
str2object
(
sm
[
1
]),
std
::
stoi
(
sm
[
2
]),
sm
[
4
]));
return
;
return
;
}
throw
std
::
exception
();
throw
std
::
invalid_argument
(
"no match"
);
}
catch
(
std
::
exception
&
e
)
{
util
::
myThrow
(
fmt
::
format
(
"Invalid name '{}' ({})"
,
name
,
e
.
what
()));}
}
void
Transition
::
initWrite
(
std
::
string
colName
,
std
::
string
object
,
std
::
string
index
,
std
::
string
value
)
{
auto
objectValue
=
Action
::
str2object
(
object
);
int
indexValue
=
std
::
stoi
(
index
);
sequence
.
emplace_back
(
Action
::
addHypothesisRelative
(
colName
,
objectValue
,
indexValue
,
value
));
cost
=
[
colName
,
objectValue
,
indexValue
,
value
](
const
Config
&
config
)
{
int
lineIndex
=
0
;
if
(
objectValue
==
Action
::
Object
::
Buffer
)
lineIndex
=
config
.
getWordIndex
()
+
indexValue
;
else
lineIndex
=
config
.
getStack
(
indexValue
);
}
catch
(
std
::
exception
&
)
{
util
::
myThrow
(
fmt
::
format
(
"Invalid name '{}'"
,
name
));}
if
(
config
.
getConst
(
colName
,
lineIndex
,
0
)
==
value
)
return
0
;
return
1
;
};
}
}
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