Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
LARA
inox
Commits
08a4c48c
Commit
08a4c48c
authored
8 years ago
by
Mikaël Mayer
Committed by
Ravi
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
olveMinChange for StringSolver (incremental)
parent
605a8155
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/leon/solvers/string/StringSolver.scala
+28
-0
28 additions, 0 deletions
src/main/scala/leon/solvers/string/StringSolver.scala
src/test/scala/leon/integration/solvers/StringSolverSuite.scala
+17
-0
17 additions, 0 deletions
...st/scala/leon/integration/solvers/StringSolverSuite.scala
with
45 additions
and
0 deletions
src/main/scala/leon/solvers/string/StringSolver.scala
+
28
−
0
View file @
08a4c48c
...
@@ -628,4 +628,32 @@ object StringSolver {
...
@@ -628,4 +628,32 @@ object StringSolver {
solveGeneralProblem
(
unbounded
.
map
(
reduceGeneralEquation
(
assignment
)(
_
))).
map
(
assignment
++
_
)
solveGeneralProblem
(
unbounded
.
map
(
reduceGeneralEquation
(
assignment
)(
_
))).
map
(
assignment
++
_
)
})
})
}
}
////////////////////////////////////////////////
//// Incremental problem extension ////
////////////////////////////////////////////////
/** Returns all subsets of i elements of a sequence. */
def
take
[
A
](
i
:
Int
,
of
:
Seq
[
A
])
:
Stream
[
Seq
[
A
]]
=
{
if
(
i
>
of
.
size
||
i
<
0
)
Stream
.
empty
if
(
i
==
of
.
size
)
Stream
(
of
)
else
if
(
i
==
0
)
Stream
(
Seq
.
empty
)
else
{
take
(
i
-
1
,
of
.
tail
).
map
(
of
.
head
+:
_
)
#:::
take
(
i
,
of
.
tail
)
}
}
/** Solves the problem while supposing that a minimal number of variables have been changed.*/
def
solveMinChange
(
p
:
Problem
,
initialMapping
:
Assignment
)
:
Stream
[
Assignment
]
=
{
// First try to see if the problem is solved. If yes, returns the initial mapping
val
initKeys
=
initialMapping
.
keys
.
toSeq
for
{
i
<-
(
initialMapping
.
size
to
0
by
-
1
).
toStream
kept
<-
take
(
i
,
initKeys
)
ifKept
=
kept
.
toSet
newProblem
=
reduceProblem
(
initialMapping
filterKeys
ifKept
)(
p
)
solution
<-
solve
(
newProblem
)
}
yield
solution
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/test/scala/leon/integration/solvers/StringSolverSuite.scala
+
17
−
0
View file @
08a4c48c
...
@@ -242,4 +242,21 @@ T2: ret Pop() -> 5"""
...
@@ -242,4 +242,21 @@ T2: ret Pop() -> 5"""
assert
(
p
.
isReadyWithin
(
2
seconds
),
"Could not solve propagate"
)
assert
(
p
.
isReadyWithin
(
2
seconds
),
"Could not solve propagate"
)
p
.
futureValue
should
not
be
(
'empty
)
p
.
futureValue
should
not
be
(
'empty
)
}
}
test
(
"solveMinChange"
)
{
implicit
val
idMap
=
MMap
[
String
,
Identifier
]()
val
problem
=
List
(
"u+v+w"
===
"akbc"
)
val
u
=
idMap
(
"u"
)
val
v
=
idMap
(
"v"
)
val
w
=
idMap
(
"w"
)
val
solutions
=
solveMinChange
(
problem
,
Map
(
u
->
"a"
,
v
->
"b"
,
w
->
"c"
))
solutions
(
0
)
should
equal
(
Map
(
v
->
"kb"
))
solutions
(
1
)
should
equal
(
Map
(
u
->
"ak"
))
(
2
to
5
).
toSet
.
map
((
i
:
Int
)
=>
solutions
(
i
))
should
equal
(
Set
(
Map
(
v
->
""
,
w
->
"kbc"
)
,
Map
(
v
->
"k"
,
w
->
"bc"
)
,
Map
(
v
->
"kb"
,
w
->
"c"
)
,
Map
(
v
->
"kbc"
,
w
->
""
)))
}
}
}
\ No newline at end of file
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