public void WriteGraph(IGraphBase graph) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};", new object[8] { graph.Id, (int)graph.Representation, (int)graph.Orientation, (int)graph.Mutability, (int)graph.EdgeInfoType, (int)graph.Type, graph.VertexCount, graph.EdgeCount }); switch (graph.Type) { case EGraphType.Bipartite: sb.AppendFormat("{0};", (graph as IBipartiteGraph).FirstPartitySize); break; } switch (graph.Representation) { case EGraphRepresentation.IncidenceMatrix: IncidenceMatrixGraph iGraph = graph as IncidenceMatrixGraph; sb.AppendFormat("{0}", iGraph.IncidenceMatrixToString()); break; } sw.WriteLine(sb.ToString()); }
protected IGraphBase AddGraphicCommand(IGraphBase cmd, IGraphBase connectedTo = null, IBaseNode baseNode = null) { cmd.Index = Index++; cmd.ConnectedTo = connectedTo; GraphicCommands.Add(cmd); MaxWidth = Math.Max(MaxWidth, cmd.HorizontalOffset); MaxHeight = Math.Max(MaxHeight, cmd.VerticalOffset); cmd.BaseNode = baseNode; return(cmd); }
bool IModelGraphics.ParseDecisionModel(IDecisionTree tree) { if (tree != null) { //IGraphBase connectedTo = AddGraphicCommand(new VerticalLine(0, 0)); IGraphBase connectedTo = AddGraphicCommand(new ModelStart(0, 0)); ParseNodes(tree.RootNode.Nodes, 0, 1, connectedTo); } //foreach (IGraphBase gb in GraphicCommands) // log.Debug(string.Format("{4} - {0}, ({1},{2}) {3}", gb.GetType().ToString(), gb.HorizontalOffset, gb.VerticalOffset, gb.Label, gb.Index)); return(GraphicCommands.Count > 0); }
protected void ParseNodes(List <IBaseNode> nodes, int xLevel, int yLevel, IGraphBase connectedTo = null) { List <IBaseNode> relevantNodes = GetRelevantNodes(nodes); List <IGraphBase> graphCmds = new List <IGraphBase>(); IGraphBase ConnectedTo = connectedTo; int branchLevel = 0; foreach (IBaseNode node in relevantNodes) { switch (node.NodeType) { case eNodeType.Expression: ConnectedTo = AddGraphicCommand(new Assignment(xLevel, yLevel++, node.Name, AssignmentImage), connectedTo, node); graphCmds.Add(ConnectedTo); branchLevel = 0; break; case eNodeType.Branch: int level = xLevel + 1 + branchLevel++; AdjustHorizontal(level); ConnectedTo = AddGraphicCommand(new HorizontalLine(level, yLevel), ConnectedTo); graphCmds.Add(AddGraphicCommand(new Branch(level, yLevel, node.Name), ConnectedTo, node)); break; } } branchLevel = 0; for (int i = 0; i < relevantNodes.Count; i++) { if (relevantNodes[i].NodeType == eNodeType.Branch && relevantNodes[i].Nodes.Count > 0) { ParseNodes(relevantNodes[i].Nodes, graphCmds[i].HorizontalOffset, graphCmds[i].VerticalOffset + 1, graphCmds[i]); } } }
public GraphItemAlreadyExistsException(IGraphBase item) { Item = item; }
public GraphItemAlreadyExistsException(IGraphBase item, string message, Exception inner) : base(message, inner) { Item = item; }
public GraphItemNotExistsException(IGraphBase item) { Item = item; }
public GraphItemNotExistsException(IGraphBase item, string message) : base(message) { Item = item; }
/* graph.Id, (int)graph.Representation, (int)graph.Orientation, (int)graph.Mutability, (int)graph.EdgeInfoType, (int)graph.Type, graph.VertexCount, graph.EdgeCount */ public bool ReadGraph(out IGraphBase graph) { int id, vertexCount, edgeCount; EGraphType type = default(EGraphType); EGraphRepresentation representation = default(EGraphRepresentation); EGraphOrientation orientation = default(EGraphOrientation); EMutability mutability = default(EMutability); EEdgeInfoType edgeInfoType = default(EEdgeInfoType); graph = null; Type typeT = Type.GetTypeFromHandle(Type.GetTypeHandle(type)), representationT = Type.GetTypeFromHandle(Type.GetTypeHandle(representation)), orientationT = Type.GetTypeFromHandle(Type.GetTypeHandle(orientation)), mutabilityT = Type.GetTypeFromHandle(Type.GetTypeHandle(mutability)), edgeInfoT = Type.GetTypeFromHandle(Type.GetTypeHandle(edgeInfoType)); string[] parts = sr.ReadLine().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (!int.TryParse(parts[0], out id) || id <= 0 || !Enum.IsDefined(representationT, representation = (EGraphRepresentation)Enum.Parse(representationT, parts[1])) || !Enum.IsDefined(orientationT, orientation = (EGraphOrientation)Enum.Parse(orientationT, parts[2])) || !Enum.IsDefined(mutabilityT, mutability = (EMutability)Enum.Parse(mutabilityT, parts[3])) || !Enum.IsDefined(edgeInfoT, edgeInfoType = (EEdgeInfoType)Enum.Parse(edgeInfoT, parts[4])) || !Enum.IsDefined(typeT, type = (EGraphType)Enum.Parse(typeT, parts[5])) || !int.TryParse(parts[6], out vertexCount) || vertexCount <= 0 || !int.TryParse(parts[7], out edgeCount) || edgeCount < 0) return false; switch (type) { case EGraphType.Bipartite: int firstPartitySize; if (!int.TryParse(parts[8], out firstPartitySize)) return false; switch (representation) { case EGraphRepresentation.IncidenceMatrix: IncidenceMatrixGraph iGraph = null; switch (orientation) { case EGraphOrientation.NonOriented: switch (edgeInfoType) { case EEdgeInfoType.Standard: iGraph = (graph = new BipartiteNonOrientedIncidenceMatrixGraph( id, vertexCount, firstPartitySize)) as IncidenceMatrixGraph; break; } break; } // nacti incidence matrix if (!iGraph.LoadIncidenceMatrix(parts[9])) return false; break; } break; } return true; }