001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/ 004 005 /* 006 * BaseVertex.java 007 * 008 * Created on November 13, 2004, 8:31 PM 009 */ 010 011 package graphlab.library; 012 013 import java.util.ArrayList; 014 015 /** 016 * The base class for all vertices. By default each vertex has a integer property 017 * named color. 018 * 019 * @author Omid Aladini 020 */ 021 022 public class BaseVertex { 023 protected BaseVertexProperties prop; 024 private ArrayList<Integer> subgraphIds = null; 025 private Integer id; 026 027 public BaseVertex(BaseVertexProperties prop) { 028 this.prop = prop; 029 } 030 031 public BaseVertex() { 032 prop = new BaseVertexProperties(0, false); 033 } 034 035 @Override 036 public String toString() { 037 return "v" + id; 038 } 039 040 public BaseVertex getCopy() { 041 return new BaseVertex(this.prop); 042 } 043 044 /** 045 * Returns the color of the vertex. 046 * 047 * @return The color associated with the vertex. 048 */ 049 public int getColor() { 050 return prop.color; 051 } 052 053 /** 054 * Sets the color of the vertex. 055 * 056 * @param color Sets col as the color of the vertex. 057 */ 058 public void setColor(int color) { 059 prop.color = color; 060 } 061 062 063 /** 064 * Returns true if the vertex is already marked. 065 * 066 * @return Returns true if the vertex is already marked. 067 */ 068 public boolean getMark() { 069 return prop.mark; 070 } 071 072 /** 073 * Flag whether it is marked. 074 * 075 * @param mark whether the vertex is marked. 076 */ 077 public void setMark(boolean mark) { 078 prop.mark = mark; 079 } 080 081 /** 082 * Returns the index of the vertex in the graph. 083 * 084 * @return Returns the index of the vertex in the graph. 085 */ 086 public int getId() { 087 return id; 088 } 089 090 /** 091 * Returns the index of the vertex in the graph that belongs to a specified subgraph. 092 * 093 * @return Returns the index of the vertex in the graph that belongs to a specified subgraph.. 094 */ 095 int getSubgraphId(int subgraphIndex) { 096 return subgraphIds.get(subgraphIndex - 1); 097 } 098 099 void informNewSubgraph() { 100 if (subgraphIds == null) 101 subgraphIds = new ArrayList<Integer>(); 102 subgraphIds.add(0); 103 } 104 105 /** 106 * Sets the index of the vertex in the graph. 107 * 108 * @param id the index of the vertex to be set. 109 */ 110 void setId(int id) { 111 this.id = id; 112 } 113 114 /** 115 * Sets the index of the vertex in the graph that belongs to a specified subgraph. 116 * 117 * @return Sets the index of the vertex in the graph that belongs to a specified subgraph.. 118 */ 119 int setSubgraphId(int subgraphIndex, int id) { 120 return subgraphIds.set(subgraphIndex - 1, id); 121 } 122 123 /** 124 * Sets properties object for this vertex; Overwrites the existing. 125 * 126 * @param prop The property object to set. 127 */ 128 public void setProp(BaseVertexProperties prop) { 129 this.prop = prop; 130 } 131 132 /** 133 * Returns property object for this vertex. 134 * 135 * @return Returns property object for this vertex. 136 */ 137 public BaseVertexProperties getProp() { 138 return prop; 139 } 140 141 }