Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ermilin E A #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ErmlinEA/Dijkstra/include/DHeap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <iostream>
#include <algorithm>
#include "Graph.h"

#define maxSize 1000
typedef int dataType;

class Data {
public:
float priorities;
};

class DHeap {
protected:
Data **keys;
int d;
int lastIdx;
public:
DHeap(int d);
DHeap(const DHeap &heap);
~DHeap();
void add(Data *&key);
void addSet(Data **key, int num);
Data* erase();
Data* erase(int i);
void transposition(int i, int j);
void surfacing(int i);
void immersion(int i);
void spudding();
int isFull();
int isEmpty();
private:
int minChild(int i);
};
16 changes: 16 additions & 0 deletions ErmlinEA/Dijkstra/include/Deijkstra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "Graph.h"
#include "DHeap.h"
#include "priorityqueue.h"
#include <cfloat>

class DataFloat : public Data {
public:
DataFloat(int v, float dist);
int v;
};

class Dijkstra {
public:
static void dijkstra(Graph *&graph, int s, float *&distance, int *&up);
};
52 changes: 52 additions & 0 deletions ErmlinEA/Dijkstra/include/Graph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <iostream>
#include <cstdlib>
#include <ctime>

#define maxSizeVertices 1000


class WeightedEdge
{
public:
int n;
int k;
float weight;
WeightedEdge(int n, int k, float weight);
};

class Graph
{
private:
int ver;
int reb;
int current_reb;
int current_ver;
WeightedEdge** edges;
int* vertices;
void GenerateVertices(int &N, int &K);
float GenerateWeight(float minRange, float maxRange);
void Cleaner();
int SearchEdge(int n, int k);
bool SearchVershinu(int ver);
void AddVershini(int n, int k);
public:
// ������������
Graph(int n);
Graph(int n, int m);
~Graph();
void GenerateGraph(float minRange, float maxRange);
void AddEdge(int N, int K, float weight);
void RemoveEdge(int N, int K);
int GetVerticesNum();
int GetEdgeSize();
int GetRealSize();
bool IsConnectivity();
WeightedEdge** GetEdgeSet();
WeightedEdge* GetEdge(int j);
float GetWeight(int N, int K);
void PrintList();
};


42 changes: 42 additions & 0 deletions ErmlinEA/Dijkstra/include/priorityqueue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "DHeap.h"

enum QueueID {
HEAP = 0,
};

class PriorityQueue {
public:
PriorityQueue() {};
virtual void push(Data *&key) = 0;
virtual Data* pop() = 0;
virtual void refresh() = 0;
virtual int isFull() = 0;
virtual int isEmpty() = 0;
};

class PriorityQueueHeap : public PriorityQueue {
protected:
DHeap *heap;
public:
PriorityQueueHeap(int d = 4);
PriorityQueueHeap(const PriorityQueueHeap &queue);
PriorityQueueHeap(Data **keys, int num, int d = 4);
~PriorityQueueHeap();
virtual void push(Data *&key);
virtual Data* pop();
virtual void refresh();
virtual int isFull();
virtual int isEmpty();
};

class QueueFactory {
public:
static PriorityQueue* createQueue(QueueID qid)
{
PriorityQueue *queue;
queue = new PriorityQueueHeap();
return queue;
}
};
122 changes: 122 additions & 0 deletions ErmlinEA/Dijkstra/samples/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "..//include/Deijkstra.h"
#include <cfloat>
#include <iostream>
#include "locale.h"

using namespace std;

int main()
{
setlocale(LC_ALL, "Rus");
Graph* graph;
int n, m, s, nmenu;
try
{
cout << "������� ���������� ������:" << endl;
cin >> n;
cout << "������� ���������� �����:" << endl;
cin >> m;
graph = new Graph(n, m);
}
catch (...)
{
return -1;
}
cout << "1. ��������� ���������" << endl;
cout << "2. ������ ����" << endl;
cin >> nmenu;
switch (nmenu)
{
case 1: {
try
{
int minRange;
int maxRange;
cout << "������� ����������� �������� ���� �����:" << endl;
cin >> minRange;
cout << "������� ������������ �������� ���� �����:" << endl;
cin >> maxRange;
graph->GenerateGraph(minRange, maxRange);
}
catch (...) {
return -1;
}
break;
}
case 2: {
int nac_ver, kon_ver;
float weight;
try
{
for (int i = 0; i < m; i++)
{
cout << "������� ��������� �������:" << endl;
cin >> nac_ver;
cout << "������� �������� �������:" << endl;
cin >> kon_ver;
cout << "������� ���:" << endl;
cin >> weight;
graph->AddEdge(nac_ver, kon_ver, weight);
}
}
catch (...)
{
return -1;
}
break;
}
}
if (!graph->IsConnectivity())
{
return -3;
}
cout << "������� ��������� ������� ��� ��������� ��������:" << endl;
cin >> s;
graph->PrintList();
cout << endl;
float *dist;
int *up;
try {
Dijkstra::dijkstra(graph, s, dist, up);
}
catch (...) {
return -2;
}
cout << n << ' ' << m << endl;
cout << s << endl;
m = graph->GetRealSize();
WeightedEdge* edge;
cout << "Matrix edges" << endl;
for (int j = 0; j < m; j++)
{
edge = graph->GetEdge(j);
cout << edge->n << ' ' << edge->k << ' ' << edge->weight << endl;
}
cout << "���������� �� �������� ������� �� i-�� �������:" << endl;
for (int i = 0; i < n; i++)
{
if (dist[i] == FLT_MAX)
{
return -4;
}
cout << s << " -> " << i << " ��������� = " << dist[i] << endl;
}
cout << endl << "���� ���� ������:" << endl;
for (int i = 0; i < n; i++)
{
int temp = i;
cout << temp << " <- ";
while (up[temp] != s)
{
cout << up[temp] << " <- ";
temp = up[temp];
}
cout << s << endl;
}
delete graph;
delete[]dist;
delete[]up;
cout << endl;
system("pause");
return 0;
}
Binary file added ErmlinEA/Dijkstra/sln/.vs/Dijkstra/v14/.suo
Binary file not shown.
Binary file added ErmlinEA/Dijkstra/sln/Debug/Dijkstra.ilk
Binary file not shown.
6 changes: 6 additions & 0 deletions ErmlinEA/Dijkstra/sln/Debug/Dijkstra.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
 Dijkstra.cpp
main.cpp
..\samples\main.cpp(39): warning C4244: аргумент: преобразование "int" в "float", возможна потеря данных
Создание кода...
Dijkstra.vcxproj -> C:\Users\Sort\Desktop\Ermiln\ErmlinEA\Dijkstra\sln\Debug\Dijkstra.exe
Dijkstra.vcxproj -> C:\Users\Sort\Desktop\Ermiln\ErmlinEA\Dijkstra\sln\Debug\Dijkstra.pdb (Full PDB)
Binary file added ErmlinEA/Dijkstra/sln/Debug/Dijkstra.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
Debug|Win32|C:\Users\Sort\Desktop\Ermiln\ErmlinEA\Dijkstra\sln\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added ErmlinEA/Dijkstra/sln/Debug/vc140.idb
Binary file not shown.
Binary file added ErmlinEA/Dijkstra/sln/Debug/vc140.pdb
Binary file not shown.
Binary file added ErmlinEA/Dijkstra/sln/Dijkstra.VC.db
Binary file not shown.
28 changes: 28 additions & 0 deletions ErmlinEA/Dijkstra/sln/Dijkstra.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dijkstra", "Dijkstra.vcxproj", "{CEE34450-5827-4CA3-AEA4-BD61959C08D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Debug|x64.ActiveCfg = Debug|x64
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Debug|x64.Build.0 = Debug|x64
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Debug|x86.ActiveCfg = Debug|Win32
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Debug|x86.Build.0 = Debug|Win32
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Release|x64.ActiveCfg = Release|x64
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Release|x64.Build.0 = Release|x64
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Release|x86.ActiveCfg = Release|Win32
{CEE34450-5827-4CA3-AEA4-BD61959C08D7}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading