Code Monkey home page Code Monkey logo

graphcoloring's Introduction

graphcoloring

Travis build status CRAN status lifecycle Coverage status

graphcoloring is a collection of graph coloring algorithms for coloring vertices of a graph such that no two adjacent vertices share the same color. The algorithms are included via the embedded ‘GraphColoring’ C++ library, https://github.com/brrcrites/GraphColoring.

Installation

You can install the released version of graphcoloring from CRAN with:

install.packages("graphcoloring")

Development version can be installed with

devtools::install_github("saurfang/graphcoloring")

Example

color_* functions operate under tidygraph family and can be used to color nodes within mutate context similar to group_* functions in tidygraph.

library(graphcoloring)
library(tidygraph)
library(ggraph)

set.seed(42)

play_islands(5, 10, 0.8, 3) %>%
  mutate(color = as.factor(color_dsatur())) %>%
  ggraph(., layout = 'kk') +
  geom_edge_link(aes(alpha = ..index..), show.legend = FALSE) +
  geom_node_point(aes(color = color), size = 7) +
  theme_graph()

graph_coloring_* functions directly take adjacency lists and returns an integer vector of assigned labels. For example, this can be used with sf::st_intersects() to color a feature collection for visualization.

library(graphcoloring)
library(USAboundaries)
library(sf)
library(ggplot2)

set.seed(48)

us_states() %>%  
  filter(!(name %in% c("Alaska", "District of Columbia", "Hawaii", "Puerto Rico"))) %>%
  mutate(
    color = st_intersects(.) %>%
      graph_coloring_dsatur() %>%
      as.factor()
  ) %>%
  ggplot() +
  geom_sf(aes(fill = color)) +
  theme_bw()

graphcoloring's People

Contributors

saurfang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

graphcoloring's Issues

CRAN release?

Hi

Just stumbled upon this, and it pretty much solve graph colouring in the way I envisioned to do it in tidygraph. Fantastic 👍

Do you have any plans for a CRAN release?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.