How to color or label vertices using jgrapht libraries?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to color or label vertices using jgrapht libraries?

Steven Barkin
I am interested in writing a graph coloring algorithm using various types of directed and undirected graph classes provided by jgrapht. None of them seem to have an easy ability to do this within the graph class itself (e.g. DirectedSimpleGraph).

My goal is to be able to traverse the graph object, and add/change various labels or colors to the vertices, without the need to store the vertex information outside the object itself - i.e. I would like to use or create methods such as "DirectedSimpleGraph.setColorToVertex(v, c), where v is a vertex. and c is the color which perhaps would be defined as an integer. Any leads or best practices advice would be greatly appreciated.


This communication is confidential and subject to and governed by the confidentiality and use restrictions contained in Saama’s Electronic Communications Disclaimer.

 


------------------------------------------------------------------------------

_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: How to color or label vertices using jgrapht libraries?

Joris Kinable
The graph libraries are generic and very well designed, so you can create your own objects as vertices or edges. Simple (untested) example:

public class Example{
  public static void main(String[] args){
    SimpleGraph<ColorableVertex, DefaultEdge> graph=new SimpleGraph<>();
    graph.addVertex(new ColorableVertex(0));
    for(ColorableVertex v : graph.vertexSet(){
      v.setColor(Color.PINK);
    }
}

public class ColorableVertex{
  Color color;
  int id;
  public ColorableVertex(int id){ ... }
  public setColor(Color color){this.color=color;}
}

br,

Joris Kinable

On Thu, Aug 6, 2015 at 7:49 PM, Steven Barkin <[hidden email]> wrote:
I am interested in writing a graph coloring algorithm using various types of directed and undirected graph classes provided by jgrapht. None of them seem to have an easy ability to do this within the graph class itself (e.g. DirectedSimpleGraph).

My goal is to be able to traverse the graph object, and add/change various labels or colors to the vertices, without the need to store the vertex information outside the object itself - i.e. I would like to use or create methods such as "DirectedSimpleGraph.setColorToVertex(v, c), where v is a vertex. and c is the color which perhaps would be defined as an integer. Any leads or best practices advice would be greatly appreciated.


This communication is confidential and subject to and governed by the confidentiality and use restrictions contained in Saama’s Electronic Communications Disclaimer.

 


------------------------------------------------------------------------------

_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users



------------------------------------------------------------------------------

_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users