Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tense on docstrings consistent #63

Merged
merged 1 commit into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/loom/alg.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ can use these functions."
(gen/pre-traverse (graph/successors g) start)))

(defn pre-span
"Return a depth-first spanning tree of the form {node [successors]}"
"Returns a depth-first spanning tree of the form {node [successors]}"
([g]
(second
(reduce
Expand Down Expand Up @@ -103,7 +103,7 @@ can use these functions."
(apply gen/bf-traverse (graph/successors g) start opts)))

(defn bf-span
"Return a breadth-first spanning tree of the form {node [successors]}"
"Returns a breadth-first spanning tree of the form {node [successors]}"
([g]
(preds->span
(reduce
Expand All @@ -119,7 +119,7 @@ can use these functions."
(gen/bf-span (graph/successors g) start)))

(defn bf-path
"Return a path from start to end with the fewest hops (i.e. irrespective
"Returns a path from start to end with the fewest hops (i.e. irrespective
of edge weights)"
[g start end & opts]
(apply gen/bf-path (graph/successors g) start end opts))
Expand Down Expand Up @@ -166,7 +166,7 @@ can use these functions."
(first (dijkstra-path-dist g start end)))

(defn- can-relax-edge?
"Test for whether we can improve the shortest path to v found so far
"Tests for whether we can improve the shortest path to v found so far
by going through u."
[[u v :as edge] weight costs]
(let [vd (get costs v)
Expand Down Expand Up @@ -248,7 +248,7 @@ can use these functions."
{}))])))

(defn dag?
"Return true if g is a directed acyclic graph"
"Returns true if g is a directed acyclic graph"
[g]
(boolean (topsort g)))

Expand Down Expand Up @@ -280,7 +280,7 @@ can use these functions."
(bf-traverse g start :f vector)))))

(defn- bellman-ford-transform
"Helper method for Johnson's algorithm. Uses Bellman-Ford to remove negative weights."
"Helper function for Johnson's algorithm. Uses Bellman-Ford to remove negative weights."
[wg]
(let [q (first (drop-while (partial graph/has-node? wg) (repeatedly gensym)))
es (for [v (graph/nodes wg)] [q v 0])
Expand Down Expand Up @@ -326,15 +326,15 @@ can use these functions."
(nodes g)))

(defn all-pairs-shortest-paths
"Find all-pairs shortest paths in a graph. Uses Johnson's algorithm for weighted graphs
"Finds all-pairs shortest paths in a graph. Uses Johnson's algorithm for weighted graphs
which is efficient for sparse graphs. Breadth-first spans are used for unweighted graphs."
[g]
(if (weighted? g)
(johnson g)
(bf-all-pairs-shortest-paths g)))

(defn connected-components
"Return the connected components of graph g as a vector of vectors. If g
"Returns the connected components of graph g as a vector of vectors. If g
is directed, returns the weakly-connected components."
[g]
(let [nb (if-not (directed? g) (graph/successors g)
Expand All @@ -359,7 +359,7 @@ can use these functions."
(== (count (first (connected-components g))) (count (nodes g))))

(defn scc
"Return the strongly-connected components of directed graph g as a vector of
"Returns the strongly-connected components of directed graph g as a vector of
vectors. Uses Kosaraju's algorithm."
[g]
(let [gt (transpose g)]
Expand All @@ -382,7 +382,7 @@ can use these functions."
(== (count (first (scc g))) (count (nodes g))))

(defn connect
"Return graph g with all connected components connected to each other"
"Returns graph g with all connected components connected to each other"
[g]
(reduce add-edges g (partition 2 1 (map first (connected-components g)))))

Expand All @@ -396,15 +396,15 @@ can use these functions."
(dec order))))))

(defn loners
"Return nodes with no connections to other nodes (i.e., isolated nodes)"
"Returns nodes with no connections to other nodes (i.e., isolated nodes)"
[g]
(let [degree-total (if (directed? g)
#(+ (in-degree g %) (out-degree g %))
#(out-degree g %))]
(filter (comp zero? degree-total) (nodes g))))

(defn distinct-edges
"Distinct edges of g. Only useful for undirected graphs"
"Returns the distinct edges of g. Only useful for undirected graphs"
[g]
(if (directed? g)
(edges g)
Expand All @@ -420,7 +420,7 @@ can use these functions."
(edges g)))))

(defn bipartite-color
"Attempt a two-coloring of graph g. When successful, returns a map of
"Attempts a two-coloring of graph g. When successful, returns a map of
nodes to colors (1 or 0). Otherwise, returns nil."
[g]
(letfn [(color-component [coloring start]
Expand Down Expand Up @@ -448,12 +448,12 @@ can use these functions."
(recur nodes (color-component coloring node))))))))

(defn bipartite?
"Return true if g is bipartite"
"Returns true if g is bipartite"
[g]
(boolean (bipartite-color g)))

(defn bipartite-sets
"Return two sets of nodes, one for each color of the bipartite coloring,
"Returns two sets of nodes, one for each color of the bipartite coloring,
or nil if g is not bipartite"
[g]
(when-let [coloring (bipartite-color g)]
Expand All @@ -466,7 +466,7 @@ can use these functions."
coloring)))

(defn- neighbor-colors
"Given a putative coloring of a graph, return the colors of all the
"Given a putative coloring of a graph, returns the colors of all the
neighbors of a given node."
[g node coloring]
(let [successors (graph/successors g node)
Expand Down Expand Up @@ -547,7 +547,7 @@ can use these functions."

(defn prim-mst-edges
"An edge-list of an minimum spanning tree along with weights that
represents an MST of the given graph. Returns the MST edge-list
represents an MST of the given graph. Returns the MST edge-list
for un-weighted graphs."
([wg]
(cond
Expand Down Expand Up @@ -590,7 +590,7 @@ can use these functions."
)))

(defn astar-path
"Return the shortest path using A* algorithm. Returns a map of predecessors."
"Returns the shortest path using A* algorithm. Returns a map of predecessors."
([g src target heur]
(let [heur (if (nil? heur) (fn [x y] 0) heur)
;; store in q => {u [heur+dist parent act est]}
Expand Down Expand Up @@ -642,7 +642,7 @@ can use these functions."
(recur g src target heur q explored)))))

(defn astar-dist
"Return the length of the shortest path between src and target using
"Returns the length of the shortest path between src and target using
the A* algorithm"
[g src target heur]
(let [path (astar-path g src target heur)
Expand All @@ -655,7 +655,7 @@ can use these functions."
dist))

(defn degeneracy-ordering
"Return sequence of vertices in degeneracy order."
"Returns sequence of vertices in degeneracy order."
[g]
(loop [ordered-nodes []
node-degs (->> (zipmap (nodes g)
Expand Down
18 changes: 9 additions & 9 deletions src/loom/alg_generic.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
seen)))))
(when-let [parent (peek stack)]
(recur successors parent (peek nbrstack)
(pop stack) (pop nbrstack) (conj seen start)))))]
(pop stack) (pop nbrstack) (conj seen start)))))]
(when-not (seen start)
(step successors start (successors start) [] [] (conj seen start)))))

;; TODO: graph-seq, analog of tree-seq

(defn pre-span
"Return a depth-first spanning tree of the form {node [successors]}"
"Returns a depth-first spanning tree of the form {node [successors]}"
[successors start & {:keys [seen return-seen] :or {seen #{}}}]
(loop [seen seen
preds {start nil}
Expand Down Expand Up @@ -216,7 +216,7 @@
:seen seen))))

(defn bf-path
"Return a path from start to end with the fewest hops (i.e. irrespective
"Returns a path from start to end with the fewest hops (i.e. irrespective
of edge weights), successors being a function that returns adjacent nodes"
[successors start end & {:as opts}]
(let [opts (merge opts {:f vector})]
Expand All @@ -226,7 +226,7 @@
(reverse (trace-path preds end)))))

(defn- shared-keys
"Return a lazy-seq of the keys that exist in both m1 and m2"
"Returns a lazy-seq of the keys that exist in both m1 and m2"
[m1 m2]
(if (< (count m2) (count m1))
(recur m2 m1)
Expand Down Expand Up @@ -461,7 +461,7 @@
(def ^Long bits-per-long (long (Long/SIZE)))

(defn ^Long bm-longs
"Return the number of longs required to store bits count bits in a bitmap."
"Returns the number of longs required to store bits count bits in a bitmap."
[bits]
(long (Math/ceil (/ bits bits-per-long))))

Expand Down Expand Up @@ -531,7 +531,7 @@
(-> ancestry :node->idx (contains? node)))

(defn ancestry-add
"Add a 'node and its 'parents associations to the 'ancestry cache."
"Adds a 'node and its 'parents associations to the 'ancestry cache."
[ancestry node & parents]
(if (ancestry-contains? ancestry node)
;; TODO Should we throw instead of drop?
Expand All @@ -549,7 +549,7 @@
(->Ancestry node->idx idx->node bitmaps))))

(defn ancestor?
"Find if the 'parenter node is an ancestor of 'childer node for the given
"Finds if the 'parenter node is an ancestor of 'childer node for the given
'ancestry cache."
[ancestry childer parenter]
(let [{:keys [node->idx bitmaps]} ancestry
Expand All @@ -561,7 +561,7 @@
pidx)))))

(defn ancestors
"Return all of the ancestors of 'child node."
"Returns all of the ancestors of 'child node."
[ancestry child]
(let [{:keys [node->idx idx->node bitmaps]} ancestry
cidx (node->idx child)]
Expand All @@ -570,6 +570,6 @@
(map idx->node))))

(defn ancestry-nodes
"Return all of the nodes in an 'ancestry."
"Returns all of the nodes in an 'ancestry."
[ancestry]
(-> ancestry :node->idx keys))
2 changes: 1 addition & 1 deletion src/loom/attr.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ thickness, etc)."
default-attr-graph-impl)

(defn attr?
"Return true if g satisfies AttrGraph"
"Returns true if g satisfies AttrGraph"
[g]
(satisfies? AttrGraph g))

Expand Down
24 changes: 12 additions & 12 deletions src/loom/flow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@


(defn residual-capacity
"Computes the residual capacity between nodes v1 and v2. Capacity
"Computes the residual capacity between nodes v1 and v2. Capacity
is a function that takes two nodes, and returns the capacity on the
edge between them, if any. Flow is the adjacency map which
edge between them, if any. Flow is the adjacency map which
represents the current flow in the network."
[capacity flow v1 v2]
(+
Expand Down Expand Up @@ -50,26 +50,26 @@

(defn is-admissible-flow?
"Verifies that a flow satisfies capacity and mass balance
constraints. Does verify that a flow is maximum."
constraints. Does verify that a flow is maximum."
[flow capacity source sink]
(and (satisfies-mass-balance? flow source sink)
(satisfies-capacity-constraints? flow capacity)))

(defn min-weight-along-path
"Given a path, represented by a sequence of nodes, and
weight-function, computes the minimum of the edge weights along the
path. If an edge on the path is missing, returns 0."
path. If an edge on the path is missing, returns 0."
[path weight-fn]
(reduce min (map #(or (apply weight-fn %) 0) (partition 2 1 path))))

(defn bf-find-augmenting-path
"Finds a shortest path in the flow network along which there remains
residual capacity. Successors is a function which, given a vertex,
returns the vertices connected by outgoing edges. Predecessors,
residual capacity. Successors is a function which, given a vertex,
returns the vertices connected by outgoing edges. Predecessors,
similarly is a function to get vertices connected by incoming
edges. Capacity is a function which takes two vertices and returns
the capacity between them. Flow is an adjacency map which contains
the current value of network flow. s is the source node, t the
edges. Capacity is a function which takes two vertices and returns
the capacity between them. Flow is an adjacency map which contains
the current value of network flow. s is the source node, t the
sink."
[successors predecessors capacity flow s t]
(gen/bf-path
Expand All @@ -83,7 +83,7 @@
Capacity is a function of two vertices, path is a sequence of
nodes, and increase is the amount by which the flow should be
augmented on this path. If at any point the increase exceeds forward
capacity, the excess is pushed in the reverse direction. An exception
capacity, the excess is pushed in the reverse direction. An exception
is thrown if the augmentation is impossible given capacity constraints."
[flow capacity path increase]
(let [vn0 (first path)
Expand All @@ -109,8 +109,8 @@
(defn edmonds-karp
"Computes the maximum flow on a network, using the edmonds-karp algorithm.
Successors is a function that returns the outgoing neighbor
vertices of a vertex. Predecessors is a function that returns the
incoming neighbor vertices for a vertex. Capacity is a function of
vertices of a vertex. Predecessors is a function that returns the
incoming neighbor vertices for a vertex. Capacity is a function of
two vertices that returns the capacity on the edge between them.
Source and sink are the unique vertices which supply and consume
flow respectively.
Expand Down
Loading