An open API service indexing awesome lists of open source software.

https://github.com/norlandz/trafficsystem

Specify a target location, the selected units in the map will move there by finding a path.
https://github.com/norlandz/trafficsystem

java javafx path pathfinding spring traffic

Last synced: about 2 months ago
JSON representation

Specify a target location, the selected units in the map will move there by finding a path.

Awesome Lists containing this project

README

          



  • Introduction



    • A 2D traffic map, & you can move an UnitObj in the Map from one Place to another (-- the Pathing Algorithm finds the way out).

    • (Pretty much like how you control the units in an RTS game.)




  • Overview (graph)




    • TrafficSystem Demo



    • https://github.com/Norlandz/TrafficSystem/assets/43581880/f2dceb0d-9387-4e95-9e9d-ad724add798d





    • https://github.com/Norlandz/TrafficSystem/assets/43581880/76c2a20f-a47d-45bc-955e-cbbf0374e00c





    • (Github md video support is very limited & its breaking the html code -- a li is added below to fix that)






  • Prior Clarification



    • This is only an Experimental project





  • How To Use



    • Left click to select an UnitObj (for movable & selectable -- controllable ones)

    • Right click to move the UnitObj to that location




  • Functionalities & Hotkeys



    • vv





      • Functionality
        Hotkey
        Description
        Activated When
        *


        select an UnitObj

        (for controllable ones)
        LButton
         
         
         


        move an UnitObj

        to Target Location
        RButton
         
         
         


        move an UnitObj

        to Multi Scheduled Target Locations
        +RButton
         
         
         


        pause Movement

        of Selected UnitObj
        s
         
         
         


        resume Movement

        of Selected UnitObj
        e
         
         
         


        cancel Movement

        of Selected UnitObj
        c
         
         
         


        select all UnitObj

        (for controllable ones)
        ^a
         
         
         


        unselect all UnitObj
        MButton
         
         
         


        select multiple UnitObj
        ^LButton
         
         
         


        select on the Main UnitObj
        !s
         
         
         


        drag an UnitObj

        (for draggable ones)
        ^!LButton
        (drag)
         
         
         


        clear Debug Shapes
        !a
         
         
         


         
         
         
         
         




      • * annotate

        • Ahk Hotkey style Notation

          • ^ = Ctrl

          • ! = Alt

          • + = Shift

          • LButton = Left Mouse Click







    • vv

      • You can send a POST request to the TrafficController Service in Port 18091, eg:


      • http://localhost:18091/v0.2.1.0/user/createTrafficLight_demo_AlignedCube?sn_row_Target=2&sn_col_Target=1&timeLength_AllowMove=100&timeLength_StopMove=100&mode_VerticalOrHorizontal=false

      • (This in turn sends (delegates) a request (internally) to the TrafficPathing)

      • & creates a TrafficLight at the specified location (for the demo)






  • Internal Design & Concept




    • Main Java class




      • PathingUtil is the central of the Pathing Algorithm


        • com.redfrog.traffic.pathing.PathingUtil.goTo_TargetLocation(UnitObj, double, double, double, GotoMode)

          is the main Api to use for Moving a (controllable) UnitObj to a Target Location




      • TrafficItemControlService is the central for creating the UnitObj (& the Map) (& Demo)




    • Algorithms







      • algorithm (function name)
        success rate
        time complexity
        description
        logic complexity


        (*some trivals)
        5% (low)

        only works for simple shapes
        O(1)
         
        1%


        get_Points_AtCloserDirection_ByAreaDet
        10%

        only works for simple shapes
        O(1)
         
        10%


        repath_by_WrapVertexSearchAlg

        _by_PermutationAndIntersection

        100%

        works in all cases

        always finds the path (unless unreachable pratically)

        always finds the shortest path
        ~O(n!)

        • uses a Permutation to brute force all the possible paths

          • (not just random brute force -- some level of logic is still required)



        • takes very Long time to calculate -- when the shape is complex

          • (optimization are added, made faster, but still not fast enough)




        45%


        repath_by_WrapVertexSearchAlg

        _by_DirectionalTangentLine_with_ShortestGotoPoint

        70%

        works in many cases

        sometimes fails to find a path (even such path exist pratically)

        often not finding the shortest path
        ~O(n)
         
        50%


        repath_by_WrapVertexSearchAlg

        _by_DirectionalTangentLine_with_Permutation

        95%~100%

        works in most/all cases

        always finds the path (should)

        may not find the shortest path
        ~O(n)

        ~O(n^2)

        ~O(n!)


        • (permutation is involved, a bit)

        • (lots other nested sub algorithms / mechanisms are added for optimization)


        65%


         
         
         
         
         




      • * the rate / complexity values are just rough estimations, no real math / benchmark






  • Technology Stack



    • JavaFx

    • Spring




  • Design Difficulties & Problems facing



    • Number Precision

      • double precision problem is a messy problem

      • in a Graphical app, precise Math calculations are required

        • eg: for the logic of Pathing Algorithm

        • eg: when you need to check for Collision

        • (tbh, this can apply to any other situations too...)





    • Collide & Stuck & Calc Hang & Both Dynamic

      • this happened many times (likey a bug)

      • I cannot tell where this is coming from:


        • inf loop/recursion;

        • some random bug (due to collision / determination of sth);

        • or there is no bug, but just the calculation is taking too long;



      • when there is only one UnitObj moving, the collision & pathing looks fine -- does not seem such bug

      • when there are 2 UnitObj moving -- especially when one of the UnitObj is doing unstoppable moving, the bug appears way more often

        • (-- if none are doing unstoppable moving -- seems fine)





    • Speed & Frame (& Incremental movements)


      • AnimationTimer is executing base on Frame, not Time.

      • This makes the calculation of Speed & detection of Collision harder.






  • Q&A



    • Where is the Comment & JavaDoc?

      • The comments I had in the Code are hideously long & unreadable. So they are all removed.

        • (Hopefully this doesnt break the code, it shouldnt but might remove some actual code accidentally during the process.)