How to judge whether a dependency is in the Relation? - database

We have a relation R(A1, A2, A3, A4)
The table is
There are three functional dependencies :
a) A4 -> A1,
b) {A2, A3} -> A4,
c) {A2, A3} -> A1
which of them are dependencies in R?

Related

How to "forward" an object property from a pair of individuals to another?

Supposing I have:
some individuals a1 and a2 from class A, b1 and b2 from class B
an object property "myProperty" from A to A or B to B.
an object property "otherProperty" from A to B
a1 :myProperty a2
a1 :otherProperty b1 and a2 :otherProperty b2
Is there a simple way to infer b1 :myProperty b2?
I am using Protégé with OWL, and I haven't found in the documentation (https://protegeproject.github.io/protege/views/object-property-characteristics) any way to do it.

A bug in PDDL AI Planning

I am trying to solve a Pacman problem using PDDL. The main thing I need to do is soft code the power duration without using functions or fluents. It returns no error but somehow I feel like it inits Powerlose(n2, n0). I never init Powerlose(n2, n0) or change Powerlose in the effect. But the initial value it gives to c is n2. So what's wrong? Thanks in advance.
You can check the problem and domain through this link:
http://editor.planning.domains/#edit_session=bD5G0tIIl1vyWDf
I tried to use exists statement instead of Powerlose(cPlus1, c) on line 34 of the domain file, it does not work. It still init c with n2. I am so confused.
Here is my domain file:
(define
(domain pacman_hard)
(:requirements :strips :typing :equality :adl)
(:types
pos int
)
(:predicates
(PacmanAt ?p - pos)
(GhostAt ?p - pos)
(FoodAt ?p - pos)
(CapsuleAt ?p - pos)
(PowerCurr ?n - int)
(PowerLose ?n1 ?n2 - int)
(PowerGain ?n1 ?n2 - int)
(Adjacent ?p1 ?p2 - pos)
)
(:action move
:parameters (?posCurr ?posNext - pos ?cPlus1 ?c ?MaxPower - int)
:precondition (and
(and
; check if there is any food left,
; which guarantees all ghosts are eaten before last food
(exists (?p - pos) (FoodAt ?p))
(PacmanAt ?posCurr)
(Adjacent ?posCurr ?posNext)
(PowerCurr ?cPlus1)
(PowerGain ?cPlus1 ?MaxPower)
)
(or
(PowerLose ?cPlus1 ?c) ;powered
(not (GhostAt ?posNext))
)
)
:effect (and
(PacmanAt ?posNext)
(not (PacmanAt ?posCurr))
; update power status accordingly/with priority
; first reduce the time of power
(when (PowerLose ?cPlus1 ?c); could minus 1
(and
(not (PowerCurr ?cPlus1))
(PowerCurr ?c)
(not (GhostAt ?posNext))
)
)
; refresh the power time if in next pos its a capsule
(when (CapsuleAt ?posNext)
(and
(not (PowerCurr ?cPlus1))
(not (PowerCurr ?c))
(PowerCurr ?MaxPower)
)
)
(not (FoodAt ?posNext))
(not (CapsuleAt ?posNext))
)
)
)
The problem file:
problem map
| 1 | 2 | 3 | 4 | 5 |
-|---|--- ---|---|---|
a| P | _ | _ | G | F |
b| _ | C | _ | G | C |
|---|---|---|---|---|
(define
(problem pacman-level-1)
(:domain pacman_hard)
(:objects
a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 - pos
n0 n1 n2 - int
)
(:init
(PacmanAt a1)
(GhostAt a4)
(GhostAt b4)
(CapsuleAt b2)
(CapsuleAt b5)
(FoodAt a5)
(PowerCurr n0)
(PowerLose n1 n0)
(PowerLose n2 n1)
(PowerGain n0 n2)
(PowerGain n1 n2)
(PowerGain n2 n2)
(Adjacent a1 a2)
(Adjacent a1 b1)
(Adjacent b1 a1)
(Adjacent b1 b2)
(Adjacent a2 a1)
(Adjacent a2 b2)
(Adjacent a2 a3)
(Adjacent b2 a2)
(Adjacent b2 b1)
(Adjacent b2 b3)
(Adjacent a3 a2)
(Adjacent a3 b3)
(Adjacent a3 a4)
(Adjacent b3 b2)
(Adjacent b3 a3)
(Adjacent b3 b4)
(Adjacent a4 a3)
(Adjacent a4 b4)
(Adjacent a4 a5)
(Adjacent b4 b3)
(Adjacent b4 a4)
(Adjacent b4 b5)
(Adjacent a5 a4)
(Adjacent a5 b5)
(Adjacent b5 b4)
(Adjacent b5 a5)
)
(:goal
; this would guarantee the pacman has eaten all food and ghosts.
(forall (?p - pos)
(and (not (FoodAt ?p)) (not (GhostAt ?p)))
)
)
)
The plan it returns:
(move a1 b1 n0 n2 n2)
(move b1 b2 n0 n2 n2)
(move b2 b3 n2 n2 n2)
(move b3 b4 n2 n1 n2)
(move b4 a4 n1 n0 n2)
(move a4 a5 n0 n2 n2)
The correct plan:
(move a1 b1) (move b1 b2) (move b2 b3) (move b3 b4) (move b4 b5) (move b5 b4) (move b4 a4) (move a4 a5)
As an aside, it's always useful to specify what planner (and it's configuration) that you're using.
I loaded your problem into the online editor:
http://editor.planning.domains/#read_session=A1Dk7n8YAz
It gave a similar plan (at least start of plan) when I tried solving. I'd suggest doing the same (Solve button is at the top), and looking at the plan. The right side shows the grounded action. First thing to notice is that your Powerlose precondition is part of an or clause, and the other part is certainly satisfied (i.e., (ghostat b1) is false). So that aspect of the precondition is satisfied.
Hopefully, this clears up what might be going on!

Comparing two arrays with For loop with python

Hello new here in stackoverflow, also I am new with the programation in Python and still learning.
I want to know why I am getting a Syntax error in the second for loop, I am trying to compare two arrays of the same lenght, when ax > bx A recive 1 point, when ax < bx B recive 1 point and where ax == bx nobody get points.
def solve(a0, a1, a2, b0, b1, b2):
A = 0
B = 0
a = [a0 , a1 ,a2]
b = [b0, b1, b2]
for x in a and for y in b:
if x > y:
pointA + 1
if x==y:
pass
else:
pointB + 1
result = [pointA, pointB]
return result
a0, a1, a2 = raw_input().strip().split(' ')
a0, a1, a2 = [int(a0), int(a1), int(a2)]
b0, b1, b2 = raw_input().strip().split(' ')
b0, b1, b2 = [int(b0), int(b1), int(b2)]
result = solve(a0, a1, a2, b0, b1, b2)
print " ".join(map(str, result))
then with some Investigation I tried:
from itertools import product
import sys
def solve(a0, a1, a2, b0, b1, b2):
A = 0
B = 0
a = [a0 , a1 ,a2]
b = [b0, b1, b2]
A = sum(1 if x>y else 0 for x, y in product(a, b))
B = sum(1 if x<y else 0 for x, y in product(a, b))
result = [A, B]
return result
a0, a1, a2 = raw_input().strip().split(' ')
a0, a1, a2 = [int(a0), int(a1), int(a2)]
b0, b1, b2 = raw_input().strip().split(' ')
b0, b1, b2 = [int(b0), int(b1), int(b2)]
result = solve(a0, a1, a2, b0, b1, b2)
print " ".join(map(str, result))
but when the Input is:
1 1 1
0 0 0
I got:
9 0
Can someone explain what I am doing wrong and why? Thank you in advance.
Regards,
R
and expects boolean values not expressions, so this: for x in a and for y in b: will never work.
You could use zip():
1 a
2 b
3 c
>>> a = [1, 2, 3]
>>> b = ['a', 'b', 'c']
>>> for x, y in zip(a, b):
... print('{} {}'.format(x, y))
...
1 a
2 b
3 c
And please correct your indentations.

How to generate all possible rankings of a document set when each document can take one of 2 types?

I need to generate possible ranking of all possible ranking of n documents. I understand that the permutations of an array {1, 2,..., n} will give me the set of all possible rankings.
My problem is a bit more complex as each document could take one of 2 possible types. Therefore, in all there are n!*2n possible rankings.
For instance, let us say I have 3 documents a, b, and c. Then possible rankings are the following:
a1 b1 c1
a1 b1 c2
a1 b2 c1
a1 b2 c2
a2 b1 c1
a2 b1 c2
a2 b2 c1
a2 b2 c2
a1 c1 b1
a1 c1 b2
a1 c2 b1
a1 c2 b2
a2 c1 b1
a2 c1 b2
a2 c2 b1
a2 c2 b2
b1 a1 c1
b1 a1 c2
b1 a2 c1
b1 a2 c2
b2 a1 c1
b2 a1 c2
...
What would be an elegant way to generate such rankings?
It's a kind of cross product between the permutations of B={a,b, ...} and the k-combinations of T{1,2} where k is the the number of elements in B. Say we take a p from Perm(B), e.g. p=(b,c,a) and a c from 3-Comb(T), e.g. c=(2,1,1) then we would merge p and c into (b2,c1,a1).
I don't really know if it's elegant but I would choose an algorithm to generate sequentially the permutations of B (cf TAOCP Volume 4 fascicle 2b) and for each permutation apply the above "product" with all the k-combinations generated sequentially (or stored in an array if k is small) (cf TAOCP Volume 4 fascicle 3a).
B={a,b,c, ... }
T={1,2}
k=length(B)
reset_perm(B)
do
p = next_perm(B)
reset_comb(T,k)
do
c = next_kcomb(T,k)
output product(p,c)
while not last_kcomb(T,k)
while not last_perm(B)

Parallel iteration over lists in makefile or CMake file

Is there a way to loop over multiple lists in parallel in a makefile or CMake file?
I would like to do something like the following in CMake, except AFAICT this syntax isn't supported:
set(a_values a0 a1 a2)
set(b_values b0 b1 b2)
foreach(a in a_values b in b_values)
do_something_with(a b)
endforeach(a b)
This would execute:
do_something_with(a0 b0)
do_something_with(a1 b1)
do_something_with(a2 b2)
I would accept an answer in either CMake or Make, though CMake would be preferred. Thanks!
Here you go:
set(list1 1 2 3 4 5)
set(list2 6 7 8 9 0)
list(LENGTH list1 len1)
math(EXPR len2 "${len1} - 1")
foreach(val RANGE ${len2})
list(GET list1 ${val} val1)
list(GET list2 ${val} val2)
message(STATUS "${val1} ${val2}")
endforeach()
As of CMake 3.17, the foreach() loop supports a ZIP_LISTS option to iterate through two (or more) lists simultaneously:
set(a_values a0 a1 a2)
set(b_values b0 b1 b2)
foreach(a b IN ZIP_LISTS a_values b_values)
message("${a} ${b}")
endforeach()
This prints:
a0 b0
a1 b1
a2 b2
In make you can use the GNUmake table toolkit to achieve this by handling the two lists as 1-column tables:
include gmtt/gmtt.mk
# declare the lists as tables with one column
list_a := 1 a0 a1 a2 a3 a4 a5
list_b := 1 b0 b1 b2
# note: list_b is shorter and will be filled up with a default value
joined_list := $(call join-tbl,$(list_a),$(list_b), /*nil*/)
$(info $(joined_list))
# Apply a function (simply output "<tuple(,)>") on each table row, i.e. tuple
$(info $(call map-tbl,$(joined_list),<tuple($$1,$$2)>))
Output:
2 a0 b0 a1 b1 a2 b2 a3 /*nil*/ a4 /*nil*/ a5 /*nil*/
<tuple(a0,b0)><tuple(a1,b1)><tuple(a2,b2)><tuple(a3,/*nil*/)><tuple(a4,/*nil*/)><tuple(a5,/*nil*/)>

Resources