All Projects → rvhuang → Linq To Astar

rvhuang / Linq To Astar

Licence: mit
A* written in C#, used with LINQ.

Projects that are alternatives of or similar to Linq To Astar

Linq2db.entityframeworkcore
Bring power of Linq To DB to Entity Framework Core projects
Stars: ✭ 166 (+90.8%)
Mutual labels:  linq, dotnet-core
Csharp Datatables Parser
C# Serverside parser for the popuplar jQuery datatables plugin.
Stars: ✭ 119 (+36.78%)
Mutual labels:  linq, dotnet-core
Linqtotwitter
LINQ Provider for the Twitter API (C# Twitter Library)
Stars: ✭ 401 (+360.92%)
Mutual labels:  linq, dotnet-core
Nhibernate Core
NHibernate Object Relational Mapper
Stars: ✭ 1,918 (+2104.6%)
Mutual labels:  linq, dotnet-core
Netfabric.hyperlinq
High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays and Span<T>.
Stars: ✭ 479 (+450.57%)
Mutual labels:  linq, dotnet-core
Hexgridutilitiesforgames
Hex-grid utilities for board and strategy games with path-finding, field-of-view, and more
Stars: ✭ 70 (-19.54%)
Mutual labels:  pathfinding
Reswplus
Unleash your resw files with this Visual Studio extension: auto generation of strongly typed static properties, support of pluralization, strongly typed string formatting, etc...
Stars: ✭ 77 (-11.49%)
Mutual labels:  dotnet-core
Xunit Logging
Logging extensions for xunit
Stars: ✭ 69 (-20.69%)
Mutual labels:  dotnet-core
Elf
The .NET 5 link forward service runs on Microsoft Azure
Stars: ✭ 68 (-21.84%)
Mutual labels:  dotnet-core
Jsonapiframework
JsonApiFramework is a fast, extensible, and portable .NET framework for the reading and writing of JSON API documents. Currently working on ApiFramework 1.0 which is a new framework that supports the many enhancements documented in the 2.0 milestone of this project while being media type agnostic but will support media types like {json:api} and GraphQL for serialization/deserialization purposes.
Stars: ✭ 85 (-2.3%)
Mutual labels:  dotnet-core
Bankflix
Aplicação que simula um banco digital, contendo a área do cliente e administrativa, permitindo depósitos e transferências entre contas do mesmo banco. | Application that simulates a digital bank, containing the customer and administrative areas, allowing deposits and transfers between accounts of the same bank.
Stars: ✭ 82 (-5.75%)
Mutual labels:  dotnet-core
Asyncworkercollection
高性能的多线程异步工具库。A collection of tools that support asynchronous methods and support high-performance multithreading.
Stars: ✭ 74 (-14.94%)
Mutual labels:  dotnet-core
Linq
linq.js - LINQ for JavaScript
Stars: ✭ 1,168 (+1242.53%)
Mutual labels:  linq
Teamcity Dotnet Plugin
TeamCity plugin for .NET Core projects
Stars: ✭ 77 (-11.49%)
Mutual labels:  dotnet-core
Linq To Bigquery
LINQ to BigQuery is C# LINQ Provider for Google BigQuery. It also enables Desktop GUI Client with LINQPad and plug-in driver.
Stars: ✭ 69 (-20.69%)
Mutual labels:  linq
Piranha.core
Piranha CMS is the friendly editor-focused CMS for .NET Core that can be used both as an integrated CMS or as a headless API.
Stars: ✭ 1,242 (+1327.59%)
Mutual labels:  dotnet-core
Scorm Learningmanagementsystem
Open Source SCORM Learning Management System demo
Stars: ✭ 68 (-21.84%)
Mutual labels:  dotnet-core
Dotnet Template Onion
Onion Architecture with .NET 5/.NET Core and CQRS/Event Sourcing following a DDD approach
Stars: ✭ 70 (-19.54%)
Mutual labels:  dotnet-core
Aspnetcore Practice
ASP.NET Core 專案練習集合,ASP.NET Core Practice Projects
Stars: ✭ 80 (-8.05%)
Mutual labels:  dotnet-core
Telegram.bot.framework
Simple framework for building Telegram bots
Stars: ✭ 73 (-16.09%)
Mutual labels:  dotnet-core

LINQ to A*

Build Status Build status License NuGet Total alerts

LINQ to A* is a POC aimed to bring LINQ to A* and other heuristic search algorithms. The library enables LINQ to be used as the query expression to the algorithm. To put it simply, A* written in C#, used with LINQ.

The library defines a set of generic APIs that can be applied to any problem, as long as the problem suits the algorithm. By taking advantage of the power of LINQ, the library is not only about re-implementing the algorithms in C#, but also giving new ability and flexibility to the algorithms.

How It Works

The following figure gives a brief overview about how the librarly works.

How it works

The initial conditions are given with the APIs called Factory Method. The solution is produced when one of query executions is called.

Getting Started

The snippet below shows the LINQ expression used to find shortest path between start and goal on a 40 * 40 map. The example utilizes the types defined in the package System.Drawing.Primitives.

var start = new Point(5, 5);
var goal = new Point(35, 35);
var boundary = new Rectangle(0, 0, 40, 40);
var unit = 1;

// The initialization of A* algorithm
// with the factory that gets possible steps from current step.
var queryable = HeuristicSearch.AStar(start, goal, (step, lv) => step.GetFourDirections(unit));

// See description below.
var solution = from step in queryable.Except(GetMapObstacles()) // 1.
               where boundary.Contains(step)                    // 2.
               orderby step.GetManhattanDistance(goal)          // 3.
               select step;

// Each step of the shortest path found by A* algorithm.
foreach (var step in solution)
{
    Console.WriteLine(step);
}

The LINQ expression consists of the following clauses:

  1. The Except() eliminates invalid steps during the process.
  2. The where clause sets up the boundary but can also be used for checking invalid steps.
  3. The orderby clause serves as h(n) (aka Heuristic) that estimates the cost of the cheapest path from n (the current step) to the goal.

If a solution is found (in deferred execution), the enumeration returns each of steps. Otherwise, an empty collection is returned.

See the document Expression Examples for more examples.

Console Examples

Live Playground

Check out Pathfinding Laboratory and play with the library.

Algorithms

Built-in Algorithms

The following algorithms are shipped with the library.

Algorithm Factory Method Remarks
A* AStar<TStep>()
Best-first Search BestFirstSearch<TStep>()
Recursive Best-first Search RecursiveBestFirstSearch<TStep>()
Iterative Deepening A* IterativeDeepeningAStar<TStep>()
Dijkstra AStar<TStep>() Without orderby clause. (v1.1.0)

User-defined Algorithms

You are able to implement and use your customized algorithms with the following steps:

  1. Create a type that implements IAlgorithm interface.
  2. Register the type and name of the algorithm with HeuristicSearch.Register<TAlgorithm>().
  3. Apply LINQ expressions to your algorithm with HeuristicSearch.Use().
// MyAlgorithmClass has to implement IAlgorithm interface.
HeuristicSearch.Register<MyAlgorithmClass>("MyAlgorithm");

var queryable = HeuristicSearch.Use("MyAlgorithm", start, goal, getFourDirections);
var solution = from step in queryable.Except(GetObstacles())
               where boundary.Contains(step)
               orderby step.GetManhattanDistance(goal)
               select step;

Algorithm Observation (v1.2.0)

The solution finding process of an algorithm can be observed by implementing the interface IAlgorithmObserverFactory<TStep> and passing its instance to the new signature of the factory method. The observed algorithm will:

  1. Create an IProgress<T> object with the IAlgorithmObserverFactory<TStep> instance, where T is AlgorithmState<TFactor, TStep>.
  2. Report the progress by creating a series of AlgorithmState<TFactor, TStep> instances and passing each of them to IProgress<T>.Report().

The following snippet shows how to observe A* algorithm.

// Implementing IAlgorithmObserverFactory<TStep> interface.
var factory = new MyAlgorithmObserverFactory();
var queryable = HeuristicSearch.AStar(start, goal, getFourDirections, null, factory);
var solution = from step in queryable.Except(GetObstacles())
               where boundary.Contains(step)
               orderby step.GetManhattanDistance(goal)
               select step;

// The algorithm starts finding the solution while reporting the progress.
var array = solution.ToArray();

The Open List Analysis of Pathfinding Laboratory largely relies on this feature.

Supported LINQ Clauses and Operations

Projection

  • Select()
  • SelectMany()

Condition

  • Where()
  • Except()
  • Contains()

Heuristic Function

  • OrderBy() - serves as heuristic function.
  • OrderByDescending() - serves as reverse heuristic function.
  • ThenBy() - serves as heuristic function but will only be referred when previous one evaluates two nodes as equal.
  • ThenByDescending() - serves as reverse heuristic function but will only be referred when previous one evaluates two nodes as equal.

Execution

The operations below provide optimized performance to replace Enumerable extensions.

  • ToArray()
  • ToList()
  • Any()
  • Count()
  • LongCount()
  • First()
  • FirstOrDefault()
  • Last()
  • LastOrDefault()

Misc

  • Reverse() - inverts the order of solution from start -> goal to goal -> start.

Roadmap

Milestone Release Date (NuGet)
1.0.0 Preview Q2 2018
1.0.0 Q3 2018
1.1.0 Q4 2018
1.2.0 Q1 2019
1.3.0 Q2 2019

Platform and Dependencies

License

The MIT License (MIT) - feel free to copy, modify and use the source code in your computer science homework (grades not guaranteed though).

Copyright © Robert Vandenberg Huang ([email protected])

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].