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
53d971e4
Commit
53d971e4
authored
9 years ago
by
Mikaël Mayer
Browse files
Options
Downloads
Patches
Plain Diff
hot fix because phase PropagateEquations inconsistent.
parent
68dcc23b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/solvers/string/StringSolver.scala
+22
-13
22 additions, 13 deletions
src/main/scala/leon/solvers/string/StringSolver.scala
with
22 additions
and
13 deletions
src/main/scala/leon/solvers/string/StringSolver.scala
+
22
−
13
View file @
53d971e4
...
...
@@ -25,14 +25,15 @@ object StringSolver {
/** Sequences of equalities such as xyz"1"uv"2" = "1, 2" */
type
Problem
=
List
[
Equation
]
def
renderStringForm
(
sf
:
StringForm
)
:
String
=
sf
match
{
case
Left
(
const
)::
Nil
=>
"\""
+
const
+
"\""
case
Right
(
id
)::
Nil
=>
id
.
toString
case
Left
(
const
)::
q
=>
"\""
+
const
+
"\"+"
+
renderStringForm
(
q
)
case
Right
(
id
)::
q
=>
id
.
toString
+
"+"
+
renderStringForm
(
q
)
case
Nil
=>
""
}
def
renderProblem
(
p
:
Problem
)
:
String
=
{
def
renderStringForm
(
sf
:
StringForm
)
:
String
=
sf
match
{
case
Left
(
const
)::
Nil
=>
"\""
+
const
+
"\""
case
Right
(
id
)::
Nil
=>
id
.
toString
case
Left
(
const
)::
q
=>
"\""
+
const
+
"\"+"
+
renderStringForm
(
q
)
case
Right
(
id
)::
q
=>
id
.
toString
+
"+"
+
renderStringForm
(
q
)
case
Nil
=>
""
}
def
renderEquation
(
e
:
Equation
)
:
String
=
{
renderStringForm
(
e
.
_1
)
+
"==\""
+
e
.
_2
+
"\""
}
...
...
@@ -75,8 +76,16 @@ object StringSolver {
}
/** Returns true if the assignment is a solution to the problem */
def
check
(
p
:
Problem
,
s
:
Assignment
)
:
Boolean
=
{
p
forall
(
eq
=>
evaluate
(
s
)(
eq
.
_1
)
==
eq
.
_2
)
def
errorcheck
(
p
:
Problem
,
s
:
Assignment
)
:
Option
[
String
]
=
{
val
res
=
p
flatMap
{
eq
=>
val
resultNotCorrect
=
reduceStringForm
(
s
)(
eq
.
_1
)
match
{
case
Left
(
a
)::
Nil
if
a
==
eq
.
_2
=>
None
case
Nil
if
eq
.
_2
==
""
=>
None
case
res
=>
Some
(
res
)
}
if
(
resultNotCorrect
.
nonEmpty
)
Some
(
renderStringForm
(
eq
.
_1
)
+
" == "
+
renderStringForm
(
resultNotCorrect
.
get
)
+
", but expected "
+
eq
.
_2
)
else
None
}
if
(
res
==
Nil
)
None
else
Some
(
res
.
mkString
(
"\n"
)
+
"\nAssignment: "
+
s
)
}
/** Concatenates constants together */
...
...
@@ -154,7 +163,7 @@ object StringSolver {
def
run
(
p
:
Problem
,
s
:
Assignment
)
=
{
ProblemSimplicationPhase
.
this
.
run
(
p
,
s
)
match
{
case
Some
((
p
,
s
))
=>
//
println("Problem before " + other.getClass.getName.substring(33) + ":" + (
p
, s))
println
(
"Problem before "
+
other
.
getClass
.
getName
.
substring
(
33
)
+
":"
+
(
renderProblem
(
p
)
,
s
))
other
.
run
(
p
,
s
)
case
None
=>
None
...
...
@@ -359,11 +368,11 @@ object StringSolver {
/** If a left-hand side of the equation appears somewhere else, replace it by the right-hand-side of this equation */
object
PropagateEquations
extends
ProblemSimplicationPhase
{
def
run
(
p
:
Problem
,
s
:
Assignment
)
:
Option
[(
Problem
,
Assignment
)]
=
{
var
newP
=
p
var
newP
=
p
.
distinct
for
((
lhs
,
rhs
)
<-
p
if
lhs
.
length
>=
2
)
{
var
indexInP
=
0
for
(
eq
@(
lhs2
,
rhs2
)
<-
newP
)
{
if
(!(
lhs2
eq
lhs
)
||
!(
rhs2
eq
rhs
))
{
if
(
(
!(
lhs2
eq
lhs
)
||
!(
rhs2
eq
rhs
))
)
{
val
i
=
lhs2
.
indexOfSlice
(
lhs
)
if
(
i
!=
-
1
)
{
val
res
=
(
lhs2
.
take
(
i
)
++
Seq
(
Left
(
rhs
))
++
lhs2
.
drop
(
i
+
lhs
.
size
),
rhs2
)
...
...
@@ -392,7 +401,7 @@ object StringSolver {
/** Composition of simplifyProblem and noLeftRightConstants */
val
forwardStrategy
=
loopUntilConvergence
(
simplifyProblem
andThen
noLeftRightConstants
andThen
PropagateMiddleConstants
andThen
PropagateEquations
)
loopUntilConvergence
(
simplifyProblem
andThen
noLeftRightConstants
andThen
PropagateMiddleConstants
/*
andThen PropagateEquations
*/
)
/** Solves the equation x1x2x3...xn = CONSTANT
...
...
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