Skip to content

Commit a426844

Browse files
paramagparamag
authored andcommitted
Parallel task processor using graphs design and code.
1 parent 09d981f commit a426844

File tree

22 files changed

+453
-8
lines changed

22 files changed

+453
-8
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
1414
/Design/LRUCache/bin/Debug
1515
/Design/LRUCache/obj/Debug
1616
/Design/ParkingLot/bin/Debug
17+
/DataStructures/Graph/bin/Debug
18+
/DataStructures/Graph/obj/Debug
19+
/DataStructures/Heap/obj/Debug
20+
/DataStructures/Heap/bin/Debug
21+
/Design/ParallelTasksProcessor/bin/Debug
22+
/Design/ParallelTasksProcessor/obj/Debug
32 KB
Binary file not shown.
44.5 KB
Binary file not shown.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algorithm.Libraries.Heap", "Algorithm.Libraries.Heap.csproj", "{668F095A-10D6-46DC-AE72-55F5101EEC55}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.Heap", "Heap\DataStructures.Libraries.Heap.csproj", "{668F095A-10D6-46DC-AE72-55F5101EEC55}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.Graph", "Graph\DataStructures.Libraries.Graph.csproj", "{6EB3565B-2658-42A7-80CB-223B6E42013A}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
1517
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{6EB3565B-2658-42A7-80CB-223B6E42013A}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DataStructures.Libraries.Graph</RootNamespace>
11+
<AssemblyName>DataStructures.Libraries.Graph</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Net.Http" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="Graph.cs" />
44+
<Compile Include="Vertex.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
48+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
49+
Other similar extension points exist, see Microsoft.Common.targets.
50+
<Target Name="BeforeBuild">
51+
</Target>
52+
<Target Name="AfterBuild">
53+
</Target>
54+
-->
55+
</Project>

DataStructures/Graph/Graph.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DataStructures.Libraries.Graph
8+
{
9+
public class Graph<TNode>
10+
{
11+
bool isCycleExists = false;
12+
13+
IList<Vertex<TNode>> GraphVertexList { get; set; }
14+
public Stack<TNode> TopologicalOrderStack { get; set; }
15+
16+
IList<Vertex<TNode>> DfsList { get; set; }
17+
18+
public Graph(IList<Vertex<TNode>> vertexList)
19+
{
20+
this.GraphVertexList = vertexList;
21+
this.TopologicalOrderStack = new Stack<TNode>();
22+
this.DfsList = new List<Vertex<TNode>>();
23+
}
24+
25+
public Graph(int[][] adjacencyArray)
26+
{
27+
}
28+
29+
public IList<Vertex<TNode>> DFS()
30+
{
31+
foreach (Vertex<TNode> node in this.GraphVertexList)
32+
{
33+
this.DFS(node);
34+
}
35+
36+
return this.DfsList;
37+
}
38+
39+
public bool IsCycleExists()
40+
{
41+
foreach (Vertex<TNode> node in this.GraphVertexList)
42+
{
43+
this.DetectCycle(node);
44+
}
45+
46+
return this.isCycleExists;
47+
}
48+
49+
private void DetectCycle(Vertex<TNode> vertex)
50+
{
51+
vertex.isVisited = true;
52+
vertex.isBeingVisited = true;
53+
54+
foreach(Vertex<TNode> v in vertex.AdjacencyList)
55+
{
56+
if(v.isBeingVisited == true)
57+
{
58+
isCycleExists = true;
59+
break;
60+
}
61+
62+
if(!v.isVisited)
63+
{
64+
this.DetectCycle(v);
65+
}
66+
}
67+
68+
vertex.isBeingVisited = false;
69+
}
70+
71+
private void DFS(Vertex<TNode> vertex)
72+
{
73+
vertex.isVisited = true;
74+
75+
foreach (Vertex<TNode> v in vertex.AdjacencyList)
76+
{
77+
if (!v.isVisited)
78+
{
79+
this.DFS(v);
80+
81+
this.TopologicalOrderStack.Push(v.node);
82+
83+
if (!this.DfsList.Contains(v))
84+
{
85+
this.DfsList.Add(v);
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Graph")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Graph")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("6eb3565b-2658-42a7-80cb-223b6e42013a")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

DataStructures/Graph/Vertex.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DataStructures.Libraries.Graph
8+
{
9+
public class Vertex<TNode>
10+
{
11+
public TNode node { get; set; }
12+
public bool isVisited;
13+
public bool isBeingVisited;
14+
15+
public Vertex<TNode> predecessor;
16+
17+
public IList<Vertex<TNode>> AdjacencyList { get; set; }
18+
19+
public Vertex()
20+
{
21+
this.AdjacencyList = new List<Vertex<TNode>>();
22+
}
23+
24+
public void AddAdjacentNode(Vertex<TNode> vertex)
25+
{
26+
this.AdjacencyList.Add(vertex);
27+
}
28+
29+
public override string ToString()
30+
{
31+
return this.node.ToString();
32+
}
33+
}
34+
}
File renamed without changes.

0 commit comments

Comments
 (0)