mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
graph
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
|
15
Esiur.Analysis/Graph/DirectedGraph.cs
Normal file
15
Esiur.Analysis/Graph/DirectedGraph.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Graph
|
||||
{
|
||||
public class DirectedGraph <T>: IGraph
|
||||
{
|
||||
public Node<T>[] Nodes { get; set; }
|
||||
public Edge<T>[] Edges { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
12
Esiur.Analysis/Graph/Edge.cs
Normal file
12
Esiur.Analysis/Graph/Edge.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Graph
|
||||
{
|
||||
public class Edge<T>
|
||||
{
|
||||
public T SourceNode { get; set; }
|
||||
public T DestinationNode { get; set; }
|
||||
}
|
||||
}
|
10
Esiur.Analysis/Graph/IGraph.cs
Normal file
10
Esiur.Analysis/Graph/IGraph.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Graph
|
||||
{
|
||||
public interface IGraph
|
||||
{
|
||||
}
|
||||
}
|
14
Esiur.Analysis/Graph/Node.cs
Normal file
14
Esiur.Analysis/Graph/Node.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Graph
|
||||
{
|
||||
public class Node<T>
|
||||
{
|
||||
public T Value { get; set; }
|
||||
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
}
|
||||
}
|
47
Esiur.Analysis/Graph/TransitionMatrix.cs
Normal file
47
Esiur.Analysis/Graph/TransitionMatrix.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Graph
|
||||
{
|
||||
public class Matrix<T> where T : struct
|
||||
{
|
||||
internal T[,] value;
|
||||
|
||||
public int Rows => value.GetLength(0);
|
||||
public int Columns => value.GetLength(1);
|
||||
|
||||
public T this[int x, int y] => value[x, y];
|
||||
|
||||
public Matrix(T[,] value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Matrix<T> Multiply<T>(Matrix<T> a, Matrix<T> b) where T:struct
|
||||
{
|
||||
|
||||
|
||||
if (a.Columns != b.Rows)
|
||||
throw new ArgumentException("`a` rows do not match `b` columns.");
|
||||
|
||||
|
||||
T[,] rt = new T[a.Rows, b.Columns];
|
||||
|
||||
for (int i = 0; i < a.Rows; i++)
|
||||
{ // aRow
|
||||
for (int j = 0; j < b.Columns; j++)
|
||||
{ // bColumn
|
||||
for (int k = 0; k < a.Columns; k++)
|
||||
{ // aColumn
|
||||
rt[i, j] += a[i, k] * b[k, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Matrix<T>(rt);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user