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
0fc25bdc2b7d
Commit
0fc25bdc2b7d
authored
16 years ago
by
ludal
Browse files
Options
Downloads
Patches
Plain Diff
remove unused files
parent
f14ebce130dd
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
debian/pycompat
+0
-1
0 additions, 1 deletion
debian/pycompat
fol.py
+0
-262
0 additions, 262 deletions
fol.py
with
0 additions
and
263 deletions
debian/pycompat
deleted
100644 → 0
+
0
−
1
View file @
f14ebce1
2
This diff is collapsed.
Click to expand it.
fol.py
deleted
100644 → 0
+
0
−
262
View file @
f14ebce1
# -*- coding: utf-8 -*-
"""
FOL.
:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: General Public License version 2 - http://www.gnu.org/licenses
Example:
x in (A,B,C,D)
y in (A,B,C)
(x == A and y == B) or (x == B and y == C)
sols = (v1:Set1,v2:Set2,...)
sola(v1,v2) | solb(v2,v3) = (v1:Set1,v2:Set2a|Set2b,v3:Set3)
sola(v1,v2) & solb(v2,v3) = (v1:Set1,v2:Set2a&Set2b,v3:Set3)
N1 or N2 : sols = [ s1 for s1 in N1.sols() ] + [ s2 for s2 in N2.sols() ]
N1 and N2 : sols = [ s1&s2 for s1 in N1.sols() for s2 in N2.sols() if s1&s2 not empty ]
V in Set : sols = (V:Set)
"""
__docformat__
=
"
restructuredtext en
"
import
bisect
def
intersect_sol
(
s1
,
s2
):
sol
=
s1
.
copy
()
sol
.
update
(
s2
)
for
n
,
v
in
s1
.
items
():
if
sol
[
n
]
!=
v
:
return
{}
return
sol
def
empty_sol
(
s
):
for
set
in
s
.
values
():
if
not
set
:
return
False
class
SolBase
(
object
):
def
__init__
(
self
):
raise
NotImplementedError
(
'
override in derived classes
'
)
def
and_sols
(
self
,
sols1
,
sols2
):
sols
=
[]
for
s1
in
sols1
:
for
s2
in
sols2
:
s
=
intersect_sol
(
s1
,
s2
)
if
s
:
sols
.
append
(
s
)
return
sols
def
or_sols
(
self
,
sols1
,
sols2
):
sols
=
sols1
[:]
for
s
in
sols2
:
if
s
not
in
sols
:
sols
.
append
(
s
)
return
sols
def
__and__
(
self
,
x
):
return
SolAnd
(
self
,
x
)
def
__or__
(
self
,
x
):
return
SolOr
(
self
,
x
)
def
__invert__
(
self
):
return
SolNot
(
self
)
def
__call__
(
self
,
domains
):
return
self
.
sols
(
domains
)
def
variables
(
self
,
upd
=
None
):
"""
Returns a dict whose keys are variables used
by this formula. if `upd` is provided it is used
instead of an empty dict and it keeps already existing
variables intact
"""
raise
NotImplementedError
class
SolNot
(
SolBase
):
def
__init__
(
self
,
s
):
self
.
sol
=
s
def
sols
(
self
,
domains
):
return
self
.
sol
.
not_sols
(
domains
)
def
__str__
(
self
):
return
"
not (
"
+
str
(
self
.
sol
)
+
"
)
"
def
variables
(
self
,
upd
=
None
):
return
self
.
sol
.
variables
(
upd
)
class
SolAnd
(
SolBase
):
def
__init__
(
self
,
s1
,
s2
):
self
.
sol
=
[]
self
.
cost
=
[]
# optimize (a and b) and c into and(a,b,c)
if
isinstance
(
s1
,
SolAnd
):
for
s
in
s1
.
sol
:
self
.
insert
(
s
)
else
:
self
.
insert
(
s1
)
# optimize a and (b and c) into and(a,b,c)
if
isinstance
(
s2
,
SolAnd
):
for
s
in
s2
.
sol
:
self
.
insert
(
s
)
else
:
self
.
insert
(
s2
)
def
insert
(
self
,
sol
):
N
=
len
(
sol
.
variables
())
idx
=
bisect
.
bisect_left
(
self
.
cost
,
N
)
self
.
cost
.
insert
(
idx
,
N
)
self
.
sol
.
insert
(
idx
,
sol
)
def
sols
(
self
,
domains
):
sols
=
self
.
sol
[
0
](
domains
)
for
s
in
self
.
sol
[
1
:]:
# domains = restrain(domains,sols)
S
=
s
(
domains
)
sols
=
self
.
and_sols
(
sols
,
S
)
return
sols
def
not_sols
(
self
,
domains
):
sols1
=
self
.
s1
.
not_sols
(
domains
)
sols2
=
self
.
s2
.
not_sols
(
domains
)
return
self
.
or_sols
(
sols1
,
sols2
)
def
__str__
(
self
):
rsols
=
[
str
(
s
)
for
s
in
self
.
sol
]
return
"
(
"
+
"
and
"
.
join
(
rsols
)
+
"
)
"
def
variables
(
self
,
upd
=
None
):
if
upd
is
None
:
upd
=
{}
for
s
in
self
.
sol
:
s
.
variables
(
upd
)
return
upd
class
SolOr
(
SolBase
):
def
__init__
(
self
,
s1
,
s2
):
self
.
s1
=
s1
self
.
s2
=
s2
def
sols
(
self
,
domains
):
sols1
=
self
.
s1
.
sols
(
domains
)
sols2
=
self
.
s2
.
sols
(
domains
)
return
self
.
or_sols
(
sols1
,
sols2
)
def
not_sols
(
self
,
domains
):
sols1
=
self
.
s1
.
not_sols
(
domains
)
sols2
=
self
.
s2
.
not_sols
(
domains
)
return
self
.
and_sols
(
sols1
,
sols2
)
def
__str__
(
self
):
return
"
(
"
+
str
(
self
.
s1
)
+
"
or
"
+
str
(
self
.
s2
)
+
"
)
"
def
variables
(
self
,
upd
=
None
):
if
upd
is
None
:
upd
=
{}
for
s
in
(
self
.
s1
,
self
.
s2
):
s
.
variables
(
upd
)
return
upd
class
SolRelation
(
SolBase
):
"""
Boolean relation between variables.
"""
def
__init__
(
self
,
*
variables
):
self
.
_variables
=
list
(
variables
)
def
variables
(
self
,
upd
=
None
):
if
upd
is
None
:
upd
=
{}
for
v
in
self
.
_variables
:
upd
[
v
.
var
]
=
0
return
upd
class
SolVar
(
SolRelation
):
"""
Simple unary relation True if var in set.
"""
def
__init__
(
self
,
V
,
s
):
self
.
var
=
V
self
.
set
=
s
def
variables
(
self
,
upd
=
None
):
if
upd
is
None
:
upd
=
{}
upd
[
self
.
var
]
=
0
return
upd
def
sols
(
self
,
domains
):
return
[
{
self
.
var
:
v
}
for
v
in
self
.
set
if
v
in
domains
[
self
.
var
]
]
def
not_sols
(
self
,
domains
):
return
[
{
self
.
var
:
v
}
for
v
in
domains
[
self
.
var
]
if
v
not
in
self
.
set
]
def
__str__
(
self
):
return
str
(
self
.
var
)
+
"
in
"
+
str
(
self
.
set
)
def
__eq__
(
self
,
v
):
return
SolEq
(
self
,
v
)
class
SolEq
(
SolRelation
):
"""
Simple equality between variables.
"""
def
sols
(
self
,
domains
):
d
=
{}
# intersect domains
for
var
in
self
.
_variables
:
for
sol
in
var
.
sols
(
domains
):
for
v
,
val
in
sol
.
items
():
c
=
d
.
setdefault
(
val
,
0
)
d
[
val
]
=
c
+
1
count
=
len
(
self
.
_variables
)
result
=
[]
for
k
,
v
in
d
.
items
():
if
v
==
count
:
r
=
{}
for
var
in
self
.
_variables
:
r
[
var
.
var
]
=
k
result
.
append
(
r
)
return
result
def
not_sols
(
self
,
domains
):
raise
NotImplementedError
def
__str__
(
self
):
return
"
==
"
.
join
(
[
v
.
var
for
v
in
self
.
_variables
]
)
def
__eq__
(
self
,
v
):
if
isinstance
(
v
,
SolVar
):
self
.
_variables
.
append
(
v
)
elif
isinstance
(
v
,
SolEq
):
self
.
_variables
+=
v
.
_variables
else
:
raise
RuntimeError
(
"
Invalid model
"
)
return
self
if
__name__
==
"
__main__
"
:
# FIXME XXX turn this into a test or remove
D
=
{
'
x
'
:
range
(
5
),
'
y
'
:
range
(
6
),
'
z
'
:
range
(
4
)
}
X
=
SolVar
(
'
x
'
,
[
1
,
2
,
3
]
)
Y
=
SolVar
(
'
y
'
,
[
4
,
5
,
6
]
)
Z
=
SolVar
(
'
z
'
,
[
2
,
3
]
)
w0
=
(
X
&
Y
)
|
Z
w1
=
X
&
Y
&
(
X
==
Z
)
print
w0
,
w0
.
sols
(
D
)
print
w1
,
w1
.
sols
(
D
)
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