{"id":22047075,"url":"https://github.com/kczulko/astar","last_synced_at":"2025-03-23T14:31:55.647Z","repository":{"id":159431280,"uuid":"133725153","full_name":"kczulko/astar","owner":"kczulko","description":"A* algorithm","archived":false,"fork":false,"pushed_at":"2018-05-17T20:26:43.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T20:43:58.126Z","etag":null,"topics":["algorithm","functional-programming","monad-transformers","monads","referentially-transparent","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kczulko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-16T21:30:43.000Z","updated_at":"2018-05-17T20:26:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"f912acd2-3fef-410c-9dc4-5d0c3a28da71","html_url":"https://github.com/kczulko/astar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kczulko%2Fastar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kczulko%2Fastar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kczulko%2Fastar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kczulko%2Fastar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kczulko","download_url":"https://codeload.github.com/kczulko/astar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245115703,"owners_count":20563213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","functional-programming","monad-transformers","monads","referentially-transparent","scala"],"created_at":"2024-11-30T13:24:48.673Z","updated_at":"2025-03-23T14:31:55.594Z","avatar_url":"https://github.com/kczulko.png","language":"Scala","readme":"# A* algorithm\n\ntable of contents\n=================\n* [description](#description)\n  * [external dependencies](#external-dependencies)\n  * [questions \u0026 answers](#questions-and-answers)\n* [HOWTO run the algorithm](#howto-run-the-algorithm)\n  * [docker](#docker)\n  * [Sbt](#sbt)\n* [sample files](#sample-files)\n* [packaging docker image](#docker-packaging)\n* [build](#build)\n* [tests](#tests)\n\ndescription\n===========\n\nThis repository contains A* algorithm implementation in Scala which is my\nresolution for the given recruitment task. A* algorithm implementation follows\n[this pseudocode](https://en.wikipedia.org/wiki/A*_search_algorithm#Pseudocode).\n\nThe program is written in pure functional style\n(except of console io effect control in main function...).\nProgram is [referentially transparent](https://en.wikipedia.org/wiki/Referential_transparency)\nand this was satisfied because of:\n* immutability - no vars or setters\n* pure functions - for the given input they return always the same result\n* recursion | `@tailrecursion` - thanks to that algorithms/functions are strict,\nsafe and self explaining\n\n## remark!\n\nDiagonal moves within the maze (next to horizontal|vertical ones) are acceptable since\nsuch constraint wasn't pointed out within the task definition. However,\nadditional docker image `kczulko/intel-a-star:0.2` was released which satisfies\nsuch constraint of vertical|horizontal moves only.\nThough it was not tested, it seems to work really well.\n\nexternal dependencies\n---------------------\n\nProject contains two external dependencies and one plugin used for docker packaging.\n\nExternal dependencies:\n\n1. [Scalaz](https://github.com/scalaz/scalaz) -\n    *An extension to the core Scala library for functional programming.* Across this\n    project were used following structures from Scalaz library:\n    * State monad - more information can be found [here](http://timperrett.com/2013/11/25/understanding-state-monad/)\n    * ListT monad transformer - more information about MT can be found [here](http://eed3si9n.com/learning-scalaz/Monad+transformers.html)\n    * sequenceS | sequenceU - in general it allows to change the type structure of `F[G[A]]` into `G[F[A]]`\n    * [Disjunction (`-\\/` or `\\/-`)](http://appliedscala.com/blog/2016/scalaz-disjunctions/)\n1. [scalatest](http://www.scalatest.org/) - testing library for Scala\n\nquestions and answers\n---------------------\n\n1) How to build and run your code.\n\n   Answers are [here](#build) and [here](#howto-run-the-algorithm)\n\n2) The heuristic that you used.\n\n   [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) was used as heuristic function.\n   Within the code it is implemented at [`Cell::distanceTo`](./src/main/scala/com/github/kczulko/a/star/model/Cell.scala) function.\n\n3) What you used for tie-breakers when you had two nodes in your priority queue with the same priority.\n\n   Priority queue wasn't used in this algorithm. `TraversableOnce[+A]::minBy` function on `Set` structure was used instead.\n\n4) What are the advantages of having a more sophisticated heuristic?  Are there any disadvantages?\n\n   Question is what does it mean *more sophisticated heuristic*? When heuristic is consistent then\n   always the shortest one path will be found. In the opposite case (when the heuristic function is not\n   monotonic) algorithm gets a little bit more complicated (we need to take under consideration nodes\n   from closed set as well and update their metrics).\n\n5) How do you know that a heuristic is admissable?  How do you know that a heuristic is monotonic?\n\n   Heuristic is admissable when *it never overestimates the actual minimal cost of reaching the goal*.\n   Heuristic is monotonic when following equation is satisfied (heuristic satisfies consistency rule):\n\n   h(x) \u003c= d(x,y) + h(y)\n\n   , where:\n     * h(x)   - heuristic value for point `x`\n     * h(y)   - heuristic value for point `y`\n     * d(x,y) - real distance between `x` and `y`\n\n   Since Euclidean distance was used as heuristic, this equation in fact satisfies\n   [triangle inequality](https://en.wikipedia.org/wiki/Triangle_inequality)\n   between `x`, `y` and `goal`.\n\n6) Does the way you break ties matter?\n\n   In case of this heuristic it doesn't.\n\nhowto run the algorithm\n=======================\n\ndocker\n------\n\nThere are prepared two versions of the docker image:\n1. `0.1` - supports moves for both diagonal and vertical|horizontal directions\n1. `0.2` - supports moves only for vertical|horizontal direction (it has not been tested)\n\nIn order to run algorithm against provided samples, please execute:\n\n```bash\n$ docker run kczulko/intel-a-star:0.1 9.txt\n```\n\nSample files from the task definition tarball were packaged to docker container so\nit is possible to choose one of them as the last argument (as it was done in the example).\n\nExecution example:\n```bash\n$ docker run kczulko/intel-a-star:0.1 4.txt\n\nInput maze:\n\n_ s _ _ _\nx x x x _\n_ x x x _\n_ _ g _ _\n\n==========\n\nMaze with path from 's' to 'g' (indicated by '*' character):\n\n_ s * * _\nx x x x *\n_ x x x *\n_ _ g * _\n\n==========\n\nPath found (rows and cols are indexed from 0):\n\nList(Cell(0,1,s), Cell(0,2,_), Cell(0,3,_), Cell(1,4,_), Cell(2,4,_), Cell(3,3,_), Cell(3,2,g))\n\n==========\n\nExpanded locations amount: 9\n\n```\n\nsbt\n---\n\n1. Install [sbt](https://www.scala-sbt.org)\n1. Go to project's root directory.\n1. Execute `sbt 'run ./src/universal/10.txt'` to run sample no. 10\n\nsample files\n============\n\nSample files used to execute an algorithm are located under `src/universal` directory.\n\nbuild\n=====\n\n```bash\n$ sbt clean compile\n``` \n\ndocker packaging\n================\n\n1. Run `sbt docker:publishLocal`\n2. Tag recently created image, e.g. `docker tag intel-a-star:0.1 \u003cusername\u003e/intel-a-star:0.1`\n3. Publish tagged image to docker hub, e.g. \n```bash\n$ docker login \u003cusername\u003e\n$ docker push \u003cusername\u003e/intel-a-star:0.1\n```\n\ntests\n=====\n\n```bash\n$ sbt test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkczulko%2Fastar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkczulko%2Fastar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkczulko%2Fastar/lists"}