Coder Social home page Coder Social logo

kri5t0fk / souvlakisearch Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 61.36 MB

App for searching places with Souvlaki (or anything). Basically Chinese Postman Problem

License: MIT License

C# 100.00%
chinese-postman-problem dijkstra-algorithm genetic-algorithm graph-algorithms map

souvlakisearch's People

Contributors

johnnybeet avatar justynagibas avatar kri5t0fk avatar swiecilom avatar swirszcz-adrian avatar

Stargazers

 avatar

Watchers

 avatar

souvlakisearch's Issues

Change Dijkstra class access to public

We need to have public access for this class for purpose of unit tests. If this class is not supposed to be tested, then you can leave it as is and close this issue.

[GA] Implement Mutation

Suggestion:

  1. Produce two random integers $i,j \in [1,n]$,
  2. then exchange the values of $v_i$ and $v_j$ to make new partnership scheme.

Example:

input: $[ABCDEF]$ (vector of vertices),
$i, j = 2, 5$,
$[AB\fbox{C}DE\fbox{F}]$ - before swap,
$[AB\fbox{F}DE\fbox{C}]$ - after swap,
return $[ABFDEC]$,

[GA] Implement Crossover

Steps

  1. Randomly select pairs of Parents
  2. For each pair -> run crossover (suggestion below)
  3. give output to Mutation (#12) or straight to Selection (#15)

Useful materials:

Suggestion - PMX (partialy-mapped crossover):

  1. input: parents:
    P1: $[\underline{ABCDEFGH}]$ (underline for genes from parent 1)
    P2: $[HEFGDABC]$
  2. Random crossover segment (should, but don't have to be next to each other)
    P1: $[\underline{ABC}\boxed{\underline{DEF}}\underline{GH}]$
    P2: $[HEF\boxed{GDA}BC]$
  3. Start Childs (leave picked vertices P1->C1, P2->C2):
    C1: $[\square\square\square|\underline{DEF}|\square\square]$
    C2: $[\square\square\square|GDA|\square\square]$
  4. Copy non-conflicting genes to Child from other Parent (P1->C2, P2->C1):
    C1: $[H\square\square|\underline{DEF}|BC]$ - $E, F$ can't be copied from P2, because are in $\{DEF\}$
    C2: $[\square\underline{BC}|GDA|\square\underline{H}]$ - $A, G$ can't be copied from P2, because are in $\{GDA\}$
  5. Fill remaining genes in Child - based on exchange-pairs from [2.] crossover segment:
    Do the change recursively, until you get vertex that wasn't in child yet.
    For C1: DEF->GDA => D->G, E->D, F->A
    For C2: GDA->DEF => G->D, D->E, A->F
    - Trying just putting (like in 4.) -> collision -> vertices in boxes need changing:
    C1: $[H\boxed{EF}|\underline{DEF}|BC]$ - E: E->D->G; F: F->A
    C2: $[\boxed{A}\underline{BC}|GDA|\boxed{G}\underline{H}]$ - A: A->F; G: G->D->E
    - After change:
    C1: $[H\hat{G}\hat{A}|\underline{DEF}|BC]$
    C2: $[\hat{F}\underline{BC}|GDA|\hat{E}\underline{H}]$
  6. Return childs:
    C1: $[HGADEFBC]$
    C2: $[FBCGDAEH]$

[GA] Const correctness in Genotype

Maybe also add get() for entire List _oddVertices?

/// <summary>
/// Genotype: a list of even number of "odd vertices".
/// Odd vertices - vertices with odd number of neighbours.
/// </summary>
private readonly List<Graph.Vertex> _oddVertices;
// Read-only Indexer for accesing the list
public Graph.Vertex this[int i]
{
get { return this._oddVertices[i]; }
}

Literature review

  • Find applied solutions (if exist).
  • Prepare a comparison of methods.
  • Prepare bibliography.
  • Add to README

[GA] Implement Selection

Basic idea

Based on Fitness score (#14) -> select individuals that will give offspring (crossover #13).
Also, after new offspring is produced -> kill weak individuals (low fitness score), so new Population (Generation #17) is stronger.

  • Parents can stay alive, and crossover with children.

Genetic Algorithm

Main GA (Genetic Algorithm) Issue - other link to that one.

Subtasks:

Algorithm Steps (approximately):

  1. Initialization #11
  2. Loop
    1. Calculate Fitness/Cost for entire population (#14)
    2. Stop/Termination condition (#23)
    3. Select solutions from population for crossover (roulette/elite) (#15)
    4. Crossover (with probability, not all individuals) (#13)
    5. Mutation (with not high probability (#12)

Useful materials:

[GA] Genotype - optimize for space usage

Currently genotype stores a list of vertices. This isn't necessarily a bad way to store data, but it is far from being space efficient - every Vertex contains both Vector2 holding position on screen and a full list of Edge objects. Therefore I'd suggest, that Genotype stores a list of indices instead, and gets all Vertex info from the reference to the original Graf object.

PLEASE make those changes on GA-algorithm-dev branch, cause I dont want to jump over three different branches, just to check for potential merges every time I open Visual Studio

[GA] Define & Implement Genotype (storage struct)

Base

Genotype consists of 2n (even number) of Odd Vertexes (road crossings): $\{A, B, C, D, E, F\}$

List of elements (permutations)

  • Genotype of one individual (candidate solution) is just a list of vertexes in any order:
    $X=[A B C D E F]$
  • each vertex only once
  • Pairs - consecutive: $pair(X_{2i}, X_{2i+1}), i={0,1,2,..}$
    soo... virtual split: $X=[A B | C D | E F] \implies$ pairs: $\{AB, CD, EF\}$

[GA] Implement Initialization

Easiest method - random:

  • Gets:
    • list of odd vertices: $[ABCDEF]$
    • size of Population
  • Returns: Population(#17): list/set of Solutions
    • generation of 1 Solution: odd vertices in random order

Example:

Input: odd vertices= $[ABCDEF]$, pop_size=4,
Return: $\{[FBACDE], [CDABFE], [EABCFD], [BFCEDA]\}$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.