Multiple python client objects connecting to one sumo simulation












0















I am new in SUMO. I have a .net, a .rou (containing 300 vehicles with vehicle depart, id, route edges attributes), a .trip and a .sumoconfig file representing a traffic scenario. I want to create these 300 vehicles as python Vehicle object generating from a Vehicle class containing other functions to communicate with each other. How can they connect dynamically to sumo and get linked to those 300 cars in the scenario? I can write a server that listens for these objects and accepts connection but what is the way of forwarding or linking them to those sumo scenario vehicles? Any hint or reference or link to code will be highly appreciated.










share|improve this question



























    0















    I am new in SUMO. I have a .net, a .rou (containing 300 vehicles with vehicle depart, id, route edges attributes), a .trip and a .sumoconfig file representing a traffic scenario. I want to create these 300 vehicles as python Vehicle object generating from a Vehicle class containing other functions to communicate with each other. How can they connect dynamically to sumo and get linked to those 300 cars in the scenario? I can write a server that listens for these objects and accepts connection but what is the way of forwarding or linking them to those sumo scenario vehicles? Any hint or reference or link to code will be highly appreciated.










    share|improve this question

























      0












      0








      0








      I am new in SUMO. I have a .net, a .rou (containing 300 vehicles with vehicle depart, id, route edges attributes), a .trip and a .sumoconfig file representing a traffic scenario. I want to create these 300 vehicles as python Vehicle object generating from a Vehicle class containing other functions to communicate with each other. How can they connect dynamically to sumo and get linked to those 300 cars in the scenario? I can write a server that listens for these objects and accepts connection but what is the way of forwarding or linking them to those sumo scenario vehicles? Any hint or reference or link to code will be highly appreciated.










      share|improve this question














      I am new in SUMO. I have a .net, a .rou (containing 300 vehicles with vehicle depart, id, route edges attributes), a .trip and a .sumoconfig file representing a traffic scenario. I want to create these 300 vehicles as python Vehicle object generating from a Vehicle class containing other functions to communicate with each other. How can they connect dynamically to sumo and get linked to those 300 cars in the scenario? I can write a server that listens for these objects and accepts connection but what is the way of forwarding or linking them to those sumo scenario vehicles? Any hint or reference or link to code will be highly appreciated.







      python client-server sumo






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 0:09









      GreenRoad-DhakaGreenRoad-Dhaka

      1816




      1816
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:



          import traci
          import traci.constants as tc

          traci.start(["sumo", "my.sumocfg"])
          traci.simulation.subscribe()
          while True:
          moveNodes = {}
          traci.simulationStep()
          # update the position of all running vehicles
          for veh, subs in traci.vehicle.getAllSubscriptionResults().items():
          moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
          # add new departed vehicles
          for v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
          traci.vehicle.subscribe(v)
          subs = traci.vehicle.getSubscriptionResults(v)
          moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])


          This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014806%2fmultiple-python-client-objects-connecting-to-one-sumo-simulation%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:



            import traci
            import traci.constants as tc

            traci.start(["sumo", "my.sumocfg"])
            traci.simulation.subscribe()
            while True:
            moveNodes = {}
            traci.simulationStep()
            # update the position of all running vehicles
            for veh, subs in traci.vehicle.getAllSubscriptionResults().items():
            moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
            # add new departed vehicles
            for v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
            traci.vehicle.subscribe(v)
            subs = traci.vehicle.getSubscriptionResults(v)
            moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])


            This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.






            share|improve this answer




























              0














              The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:



              import traci
              import traci.constants as tc

              traci.start(["sumo", "my.sumocfg"])
              traci.simulation.subscribe()
              while True:
              moveNodes = {}
              traci.simulationStep()
              # update the position of all running vehicles
              for veh, subs in traci.vehicle.getAllSubscriptionResults().items():
              moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
              # add new departed vehicles
              for v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
              traci.vehicle.subscribe(v)
              subs = traci.vehicle.getSubscriptionResults(v)
              moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])


              This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.






              share|improve this answer


























                0












                0








                0







                The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:



                import traci
                import traci.constants as tc

                traci.start(["sumo", "my.sumocfg"])
                traci.simulation.subscribe()
                while True:
                moveNodes = {}
                traci.simulationStep()
                # update the position of all running vehicles
                for veh, subs in traci.vehicle.getAllSubscriptionResults().items():
                moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
                # add new departed vehicles
                for v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
                traci.vehicle.subscribe(v)
                subs = traci.vehicle.getSubscriptionResults(v)
                moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])


                This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.






                share|improve this answer













                The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:



                import traci
                import traci.constants as tc

                traci.start(["sumo", "my.sumocfg"])
                traci.simulation.subscribe()
                while True:
                moveNodes = {}
                traci.simulationStep()
                # update the position of all running vehicles
                for veh, subs in traci.vehicle.getAllSubscriptionResults().items():
                moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
                # add new departed vehicles
                for v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
                traci.vehicle.subscribe(v)
                subs = traci.vehicle.getSubscriptionResults(v)
                moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])


                This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 5 at 12:25









                MichaelMichael

                1,6941717




                1,6941717
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014806%2fmultiple-python-client-objects-connecting-to-one-sumo-simulation%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Angular Downloading a file using contenturl with Basic Authentication

                    Monofisismo

                    Olmecas