Created
May 23, 2011 10:05
-
-
Save kencoba/986500 to your computer and use it in GitHub Desktop.
check graph isomorphism (not complete)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.contrib.graph] | |
'[clojure.test]) | |
(def empty-graph (struct directed-graph #{} {})) | |
(def test-graph-1 | |
(struct directed-graph | |
#{:a :b :c :d :e} | |
{:a #{:b :c} | |
:b #{:a :c} | |
:c #{:d :e} | |
:d #{:a :b} | |
:e #{:d}})) | |
(def test-graph-2 | |
(struct directed-graph | |
#{:a2 :b2 :c2 :d2 :e2} | |
{:a2 #{:b2} | |
:b2 #{:a2} | |
:c2 #{:d2} | |
:d2 #{:a2} | |
:e2 #{:d2}})) | |
(defn get-nodes-map | |
[n-domain n-range] | |
{:pre [(vector? n-domain) | |
(vector? n-range) | |
(= (count n-domain) (count n-range))]} | |
(apply merge (map hash-map n-domain n-range))) | |
(defn get-mapped-nodes [nodes nodes-map] | |
(set (for [n nodes] | |
(nodes-map n)))) | |
(defn get-mapped-neighbors [neighbors nodes-map] | |
(apply merge | |
(for [node-dom (keys neighbors)] | |
(hash-map | |
(nodes-map node-dom) | |
(set (for [neighbor (neighbors node-dom)] | |
(nodes-map neighbor))))))) | |
(defn get-mapped-graph [graph-from graph-to] | |
"Return a graph with same structure with graph-from, | |
but node names with graph-to " | |
(let [nodes-map (get-nodes-map (vec (:nodes graph-from)) | |
(vec (:nodes graph-to)))] | |
(struct directed-graph | |
(get-mapped-nodes (:nodes graph-from) nodes-map) | |
(get-mapped-neighbors (:neighbors graph-from) nodes-map)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment