Главная страница

ргр по алгоритмам и структурам данных. АиСД РГР, ключников. Разработка атд Простой граф


Скачать 135.4 Kb.
НазваниеРазработка атд Простой граф
Анкорргр по алгоритмам и структурам данных
Дата20.12.2022
Размер135.4 Kb.
Формат файлаdocx
Имя файлаАиСД РГР, ключников.docx
ТипДокументы
#854773
страница9 из 12
1   ...   4   5   6   7   8   9   10   11   12

AbstractGraph.cs


using System.Collections.Generic;

using System;
namespace АиСД_РГР

{

abstract class AbstractGraph // простой граф - абстрактный класс

{

public bool Type; //true == M-граф, иначе - L-граф

public bool Oriented; //true == ориентированный

public bool Weighted;

public List> Vertexes;

public int CurrentIndex;

public int EdgesCount;//количество ребер

public List> Adj; //вектор смежности

public Edge[,] Matrix;

internal abstract class IteratorAllEdges // итератор ребер

{

protected int I;

protected int J;

protected bool State; //0 - не установлен, 1 - установлен

protected AbstractGraph ItGraph;
public IteratorAllEdges(AbstractGraph g)

{

State = false;

// ItGraph = g;

I = 0;

J = 0;

}
public static IteratorAllEdges MakeIt(AbstractGraph g)

{

if (g.Type == false)

{

var q = new LGraph.LIteratorAllEdges(g);

return q;

}
else

{

var q = new MGraph.MIteratorAllEdges(g);

return q;

}

}
public abstract bool Beg();

public abstract bool End();

public abstract void Next();

public abstract Edge Input();

}
internal abstract class IteratorOutEdge // итератор исходящих ребер

{

protected Vertex ItVertex;

protected bool State;

protected int J;

protected AbstractGraph ItGraph;
public IteratorOutEdge(Vertex v, AbstractGraph g)

{

//ItVertex = v;

State = false;

J = 0;

//ItGraph = g;

}
public static IteratorOutEdge MakeIt(Vertex v, AbstractGraph g)

{

if (g.Type == false)

{

//IteratorOutEdge q;

var q = new LGraph.LIteratorOutEdge(v, g);

return q;

}
else

{

var q = new MGraph.MIteratorOutEdge(v, g);

return q;

}

}
public abstract bool Beg();

public abstract bool End();

public abstract void Next();

public abstract Edge Input();

}
internal abstract class IteratorInputEdge // итератор входящих ребер

{

protected Vertex ItVertex;

protected bool State;

protected int J;

protected int I;

protected AbstractGraph ItGraph;
public IteratorInputEdge(Vertex v, AbstractGraph g)

{

State = false;

//ItVertex = v;

//ItGraph = g;

I = 0;

J = 0;

}
public static IteratorInputEdge MakeIt(Vertex v, AbstractGraph g)

{

if (g.Type == false)

{

//IteratorOutEdge q;

var q = new LGraph.LIteratorInputEdge(v, g);

return q;

}
else

{

var q = new MGraph.MIteratorInputEdge(v, g);

return q;

}

}
public abstract bool Beg();

public abstract bool End();

public abstract void Next();

public abstract Edge Input();

}
public class IteratorVertexes // итератор вершин

{

private bool VS;

private int CurrentCur;

private AbstractGraph iGG;
public IteratorVertexes(AbstractGraph g)

{

VS = false;

iGG = g;

CurrentCur = 0;

}
public Vertex Beg()

{

if (iGG.Vertexes.Count == 0)

{

VS = false;

return null;

}
else

{

VS = true;

CurrentCur = 0;

return iGG.Vertexes[0];

}

}
public Vertex End()

{

if (iGG.Vertexes.Count == 0)

{

VS = false;

return null;

}
else

{

VS = true;

CurrentCur = iGG.Vertexes.Count - 1;

return iGG.Vertexes[iGG.Vertexes.Count - 1];

}

}
public void Next()//++

{

if (VS)

CurrentCur++;

if (CurrentCur >= iGG.Vertexes.Count)

{

VS = false;

}

}
public Vertex Input()//*

{

if (VS == false)

return null;

else

{

return iGG.Vertexes[CurrentCur];

}

}

}
public AbstractGraph()

{

CurrentIndex = 0;

Vertexes = new List>();

Matrix = new Edge[0, 0];

Oriented = false;

Weighted = false;

}
public AbstractGraph(bool D, bool F)

{

Type = F;

EdgesCount = 0;

CurrentIndex = 0;

Vertexes = new List>();

Matrix = new Edge[0, 0];

Oriented = D;

}
static public AbstractGraph MakeGraph(int V, bool D, bool F)

{

if (!F)

{

return new LGraph(V, D, F);

}

else

{

return new MGraph(V, D, F);

}

}
static public void Clear(AbstractGraph graph)

{

graph = null;

}
public Vertex GetVertex(int i)

{

if (i >= Vertexes.Count)

return null;

return Vertexes[i];

}
static public AbstractGraph MakeGraph(int V, int E, bool D, bool F)

{

if (!F)

{

return new LGraph(V, E, D, F);

}

else

{

return new MGraph(V, E, D, F);

}

}
public bool Directed()

{

return Oriented;

}
public float Saturation()

{

if (Oriented)

{

float koef = EdgesCount / ((float)(Vertexes.Count * (Vertexes.Count - 1)));

return koef;
}

else

{

float koef = EdgesCount / ((float)(Vertexes.Count * (Vertexes.Count - 1)) / 2);

Console.WriteLine("VertexesCount: " + Vertexes.Count);

return koef;

}


}
public int V()

{

return Vertexes.Count;

}
public int E()

{

return EdgesCount;

}
public abstract Edge AddEdge(Vertex v1, Vertex v2);

public abstract bool DeleteVertex(Vertex vertex);

public abstract Vertex AddVertex();

public abstract bool DeleteEdge(Vertex vertex1, Vertex vertex2);
}

}
    1. 1   ...   4   5   6   7   8   9   10   11   12


написать администратору сайта