Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-03-2022 08:42 AM
Hello
I have the following function that I found in this Ref
I want to use this function to find the minimum dominating set. How can I execute this in neo4j?
function CYPHERGreedyAlgorithm
MATCH(h)
SET h.whiteness = 1
SET h.blackness = 0
WITH h
OPTIONAL MATCH(j)
WHERE NOT (j){>()
SET j.blackness = 1
SET j.whiteness = 0
WITH j
MATCH (n){>(m)
WHERE n.blackness <> 1
WITH collect(m) as neighbourhood, n
WITH reduce(totalweight = n.whiteness, j in neighbourhood | totalweight + j.whiteness) as weightings, n
WITH n, weightings
ORDER BY weightings desc limit 1
MATCH (n1){>(m1)
WHERE n1.blackness <> 1
WITH collect(m1) as neighbourhood, n1
WITH reduce(totalweight = n1.whiteness, j in neighbourhood | totalweight + j.whiteness) as weightings, n1
WITH n1, weightings
ORDER BY weightings desc limit 1
MATCH(n1){>(m1)
WHERE m1.blackness <> 1
SET n1.blackness = 1
SET n1.whiteness = 0
SET m1.whiteness = 0
WITH n1
MATCH (k)
WHERE k.whiteness = 1
RETURN count(distinct(k)) as countOfRemainingWhiteNodes
end function
07-03-2022 04:05 PM
Hi @samasamaan
First, you can easily create functions with apoc.
After that, it is best to move to Java without apoc.
This is a sample code on the APOC doc.
CALL apoc.custom.declareProcedure(
'powers(input::INT, power::INT) :: (answer::INT)',
'UNWIND range(0, $power) AS power
RETURN $input ^ power AS answer'
);
Custom, Cypher Based Procedures and Functions
https://neo4j.com/labs/apoc/4.4/cypher-execution/cypher-based-procedures-functions/
User-defined functions
https://neo4j.com/docs/java-reference/current/extending-neo4j/functions/
07-04-2022 09:19 AM
Thanks for your reply. My question is: Should I program the algorithm in Java? Why I can’t use the Cypher that I mentioned in the question? Please I need help in this to solve the SDN controller placement problem using neo4j and the dominating set algorithm.
07-05-2022 08:50 AM
I found this link Minimum Dominating Set . Can this be a good reference to add this algorithm to the GDS library?
All the sessions of the conference are now available online