Skip to content
 
 

Repository files navigation

Build Maintainability Test Coverage

VisualGraphs

Usage

#simple not weighted graph
# json import
graph = Graph.load_from_json(path)

#initialization from hash
hash_graph = {1 => [2, 3], 2 => [1, 4]}
graph = Graph.adjacency_list_init(hash_graph)

graph.vertices #return list of vertices
graph.edges #return list of edges
#adding new vertex (vertex could be numbers,chars .etc)
# if vertex is already exists it will not be added
graph.insert_vertex(new_vertex)
#adding new edge for simple Graph
# vertices will also be included in vertices list of graph if they are not there
# also add second_vertex to adjacency_list of first_vertex 
graph.insert_edge([first_vertex, second_vertex])
graph.output_to_standard_stream # prints graph(adjacency_list)
#will create(overwrite) json_file and save adjacency_list in it
#json_file name must ends with .json 
graph.dump_to_json(path_to_file)
WeightedGraph - weighted_adjacency_list

# json import
# will raise error if 
graph = WeightedGraph.load_from_json(path)

#initialization from hash
hash_graph = {1 => [[2, 3]], 2 => [[1, 4]]}
graph = WeightedGraph.adjacency_list_init(hash_graph)

graph.vertices #return list of vertices
graph.edges #return list of edges

#v1,v2 vertices,w - weight
graph.insert_edge([v1,[v2,w]])

Data formats

for simple not weighted Graph class
{
  "1":[2],
  "2":[3],
  "3":[1,4]
  "4": []
}

hash = {1 => [2,3]}

for weightedGraph 
{
  "1":[[2,1]],
  "2":[[3,4]],
  "3":[[1,5],[4,6]]
  "4": []
}

hash = {1 => [[2,3], [3,4]]}

Installation

Add this line to your application's Gemfile:

gem 'visual_graphs'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install visual_graphs

Usage

TODO: Write usage instructions here

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/visual_graphs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the VisualGraphs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages