Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RQL
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
cubicweb
RQL
Commits
5582718a40ea
Commit
5582718a40ea
authored
16 years ago
by
ludal
Browse files
Options
Downloads
Patches
Plain Diff
more factorisation and WIP on other solver
parent
7d7375eadf5c
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
analyze.py
+49
-17
49 additions, 17 deletions
analyze.py
with
49 additions
and
17 deletions
analyze.py
+
49
−
17
View file @
5582718a
...
...
@@ -16,8 +16,8 @@
from
pprint
import
pprint
class
C
onstraints
(
object
):
class
C
SPProblem
(
object
):
def
__init__
(
self
):
self
.
constraints
=
[]
self
.
domains
=
{}
self
.
scons
=
[]
...
...
@@ -20,7 +20,21 @@
def
__init__
(
self
):
self
.
constraints
=
[]
self
.
domains
=
{}
self
.
scons
=
[]
self
.
output
=
StringIO
()
def
get_output
(
self
):
return
self
.
output
.
getvalue
()
def
printer
(
self
,
*
msgs
):
self
.
output
.
write
(
'
'
.
join
(
str
(
msg
)
for
msg
in
msgs
))
self
.
output
.
write
(
'
\n
'
)
def
solve
(
self
):
repo
=
Repository
(
self
.
domains
.
keys
(),
self
.
domains
,
self
.
get_constraints
())
solver
=
Solver
(
printer
=
self
.
printer
)
sols
=
solver
.
solve
(
repo
,
verbose
=
(
True
or
self
.
debug
))
return
sols
def
add_var
(
self
,
name
,
values
):
self
.
domains
[
name
]
=
fd
.
FiniteDomain
(
values
)
...
...
@@ -90,6 +104,9 @@
if
len
(
dom
)
==
1
:
return
1
return
0
def
accept
(
self
,
vis
):
vis
.
visit_eq
(
self
)
class
_true
(
object
):
def
__str__
(
self
):
...
...
@@ -98,6 +115,8 @@
pass
def
simplify
(
self
,
doms
):
return
1
def
accept
(
self
,
vis
):
vis
.
visit_true
(
self
)
class
_false
(
object
):
def
__str__
(
self
):
...
...
@@ -106,6 +125,8 @@
pass
def
simplify
(
self
,
doms
):
return
-
1
def
accept
(
self
,
vis
):
vis
.
visit_false
(
self
)
class
_eqv
(
object
):
def
__init__
(
self
,
vars
):
...
...
@@ -116,6 +137,8 @@
s
+=
self
.
vars
def
simplify
(
self
,
doms
):
return
0
def
accept
(
self
,
vis
):
vis
.
visit_eqv
(
self
)
class
_and
(
object
):
def
__init__
(
self
):
...
...
@@ -127,6 +150,8 @@
def
get_vars
(
self
,
s
):
for
t
in
self
.
cond
:
t
.
get_vars
(
s
)
def
accept
(
self
,
vis
):
vis
.
visit_and
(
self
)
def
simplify
(
self
,
doms
):
cd
=
[]
...
...
@@ -168,5 +193,7 @@
self
.
cond
=
[
_false
()
]
return
-
1
return
0
def
accept
(
self
,
vis
):
vis
.
visit_or
(
self
)
...
...
@@ -172,5 +199,19 @@
class
_Constraints
(
object
):
class
DistributeVisitor
(
object
):
def
visit_and
(
self
,
node
):
pass
def
visit_or
(
self
,
node
):
pass
def
visit_true
(
self
,
node
):
pass
def
visit_false
(
self
,
node
):
pass
def
visit_eq
(
self
,
node
):
pass
def
visit_eqv
(
self
,
node
):
pass
class
_CSPProblem
(
object
):
def
__init__
(
self
):
self
.
constraints
=
[]
self
.
op
=
_and
()
...
...
@@ -307,19 +348,10 @@
print
"
CONSTRAINTS:
"
pprint
(
constraints
.
scons
)
domains
=
constraints
.
get_domains
()
# solve the problem and check there is at least one solution
kwargs
=
{}
if
True
or
self
.
debug
:
# capture solver output
solve_debug
=
StringIO
()
def
printer
(
*
msgs
):
solve_debug
.
write
(
'
'
.
join
(
str
(
msg
)
for
msg
in
msgs
))
solve_debug
.
write
(
'
\n
'
)
kwargs
[
'
printer
'
]
=
printer
r
=
Repository
(
domains
.
keys
(),
domains
,
constraints
.
get_constraints
())
solver
=
Solver
(
**
kwargs
)
sols
=
solver
.
solve
(
r
,
verbose
=
(
True
or
self
.
debug
))
sols
=
constraints
.
solve
()
if
not
sols
:
rql
=
node
.
as_string
(
'
utf8
'
,
self
.
kwargs
)
ex_msg
=
'
Unable to resolve variables types in
"
%s
"
!!
'
%
(
rql
,)
if
True
or
self
.
debug
:
...
...
@@ -322,8 +354,8 @@
if
not
sols
:
rql
=
node
.
as_string
(
'
utf8
'
,
self
.
kwargs
)
ex_msg
=
'
Unable to resolve variables types in
"
%s
"
!!
'
%
(
rql
,)
if
True
or
self
.
debug
:
ex_msg
+=
'
\n
%s
'
%
(
solve_debug
.
getvalue
(),)
ex_msg
+=
'
\n
%s
'
%
(
constraints
.
get_output
(),)
raise
TypeResolverException
(
ex_msg
)
node
.
set_possible_types
(
sols
,
self
.
kwargs
,
self
.
var_solkey
)
...
...
@@ -350,7 +382,7 @@
return
types
def
_init_stmt
(
self
,
node
):
pb
=
C
onstraints
()
pb
=
C
SPProblem
()
# set domain for the all variables
for
var
in
node
.
defined_vars
.
itervalues
():
pb
.
add_var
(
var
.
name
,
self
.
_base_domain
)
...
...
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