<commit_before>/*
 * Copyright (c) 2015 <NAME>
 *
 * See te LICENSE file in the project root for further copyright information.
 */

package info.andreaswolf.roadhopper.simulation

import akka.actor.{ActorRef, ActorSystem, Props}
import akka.pattern.ask
import akka.util.Timeout
import com.graphhopper.util.CmdArgs
import com.graphhopper.util.shapes.GHPoint
import info.andreaswolf.roadhopper.RoadHopper
import info.andreaswolf.roadhopper.road.{Route, RouteFactory}
import info.andreaswolf.roadhopper.simulation.SimulationParameters.PedalParameters
import info.andreaswolf.roadhopper.simulation.control.{PIDController, PT1}
import info.andreaswolf.roadhopper.simulation.driver.{TargetVelocityEstimator, VelocityController}
import info.andreaswolf.roadhopper.simulation.signals.SignalBus.SubscribeToSignal
import info.andreaswolf.roadhopper.simulation.signals.{SignalBus, SignalState}
import info.andreaswolf.roadhopper.simulation.vehicle.{Brake, VehicleFactory, VehicleParameters}

import scala.collection.mutable
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}


object SignalBasedSimulation extends App {
	/**
	 * Standalone app for testing the signal-based routing. To use RoadHopper in an actual use case, start
	 * [[info.andreaswolf.roadhopper.server.RoadHopperServer]] instead.
	 */
	override def main(args: Array[String]): Unit = {
		val cmdArgs = CmdArgs.read(args)
		val roadHopperInstance = new RoadHopper
		roadHopperInstance.forServer().init(cmdArgs)
		roadHopperInstance.importOrLoad()

		val routeFactory = new RouteFactory(roadHopperInstance)
		val points: List[GHPoint] = List(new GHPoint(49.010796, 8.375444), new GHPoint(49.01271, 8.418016))
		val route = routeFactory.simplify(routeFactory.getRoute(points).parts, 2.0)

		val simulation: SignalBasedSimulation = new SignalBasedSimulation(new SimulationParameters(
			pedal = new PedalParameters(gasPedalGain = 500.0, brakePedalGain = -500.0),
			vehicle = VehicleParameters.CompactCar,
			route = route
		), new SimulationResult)
		simulation.start()
	}
}

class SignalBasedSimulation(val simulationParameters: SimulationParameters, override val result: SimulationResult)
	extends Simulation(result) {

	/**
	 * Compatibility constructor to instantiate the simulation with just a route. A default set of parameters will be
	 * used
	 */
	def this(route: Route, result: SimulationResult) {
		this(new SimulationParameters(
			pedal = new PedalParameters(gasPedalGain = 500.0, brakePedalGain = -500.0),
			vehicle = VehicleParameters.CompactCar,
			route = route
		), result)
	}

	val route = simulationParameters.route

	val actorSystem = ActorSystem.create("signals")

	import actorSystem.dispatcher
	implicit val timeout = Timeout(10 seconds)

	val timer = actorSystem.actorOf(Props(new TwoStepSimulationTimer), "timer")
	val signalBus = actorSystem.actorOf(Props(new SignalBus(timer)), "signalBus")

	val vehicle = new VehicleFactory(actorSystem, timer, signalBus).createVehicle(VehicleParameters.CompactCar)

	val journey = actorSystem.actorOf(Props(new SignalsJourneyActor(timer, signalBus, simulationParameters.route)), "journey")
	val velocityEstimator = actorSystem.actorOf(Props(new TargetVelocityEstimator(signalBus, journey)))
	val driver = actorSystem.actorOf(Props(new VelocityController(signalBus)))
	val velocityController = actorSystem.actorOf(Props(
		new PIDController("v_diff", "alpha_in",
			simulationParameters.velocityController.proportionalGain, simulationParameters.velocityController.integratorGain,
			simulationParameters.velocityController.differentiatorGain, signalBus)
	))

	val gasPedal = actorSystem.actorOf(Props(new PT1("alpha_in", "alpha", 10, simulationParameters.pedal.gasPedalGain, 0.0, signalBus)))
	val brakePedal = actorSystem.actorOf(Props(new PT1("alpha_in", "beta", 10, simulationParameters.pedal.brakePedalGain, 0.0, signalBus)))
	val brake = actorSystem.actorOf(Props(new Brake("beta", "beta*", 0, signalBus)))

	val signalLogger = actorSystem.actorOf(Props(new SignalLogger(signalBus, result, 50)))
<commit_msg>[TASK] Increase PT1 delays for pedals and brake<commit_after>/*
 * Copyright (c) 2015 <NAME>
 *
 * See te LICENSE file in the project root for further copyright information.
 */

package info.andreaswolf.roadhopper.simulation

import akka.actor.{ActorRef, ActorSystem, Props}
import akka.pattern.ask
import akka.util.Timeout
import com.graphhopper.util.CmdArgs
import com.graphhopper.util.shapes.GHPoint
import info.andreaswolf.roadhopper.RoadHopper
import info.andreaswolf.roadhopper.road.{Route, RouteFactory}
import info.andreaswolf.roadhopper.simulation.SimulationParameters.PedalParameters
import info.andreaswolf.roadhopper.simulation.control.{PIDController, PT1}
import info.andreaswolf.roadhopper.simulation.driver.{TargetVelocityEstimator, VelocityController}
import info.andreaswolf.roadhopper.simulation.signals.SignalBus.SubscribeToSignal
import info.andreaswolf.roadhopper.simulation.signals.{SignalBus, SignalState}
import info.andreaswolf.roadhopper.simulation.vehicle.{Brake, VehicleFactory, VehicleParameters}

import scala.collection.mutable
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}


object SignalBasedSimulation extends App {
	/**
	 * Standalone app for testing the signal-based routing. To use RoadHopper in an actual use case, start
	 * [[info.andreaswolf.roadhopper.server.RoadHopperServer]] instead.
	 */
	override def main(args: Array[String]): Unit = {
		val cmdArgs = CmdArgs.read(args)
		val roadHopperInstance = new RoadHopper
		roadHopperInstance.forServer().init(cmdArgs)
		roadHopperInstance.importOrLoad()

		val routeFactory = new RouteFactory(roadHopperInstance)
		val points: List[GHPoint] = List(new GHPoint(49.010796, 8.375444), new GHPoint(49.01271, 8.418016))
		val route = routeFactory.simplify(routeFactory.getRoute(points).parts, 2.0)

		val simulation: SignalBasedSimulation = new SignalBasedSimulation(new SimulationParameters(
			pedal = new PedalParameters(gasPedalGain = 500.0, brakePedalGain = -500.0),
			vehicle = VehicleParameters.CompactCar,
			route = route
		), new SimulationResult)
		simulation.start()
	}
}

class SignalBasedSimulation(val simulationParameters: SimulationParameters, override val result: SimulationResult)
	extends Simulation(result) {

	/**
	 * Compatibility constructor to instantiate the simulation with just a route. A default set of parameters will be
	 * used
	 */
	def this(route: Route, result: SimulationResult) {
		this(new SimulationParameters(
			pedal = new PedalParameters(gasPedalGain = 500.0, brakePedalGain = -500.0),
			vehicle = VehicleParameters.CompactCar,
			route = route
		), result)
	}

	val route = simulationParameters.route

	val actorSystem = ActorSystem.create("signals")

	import actorSystem.dispatcher
	implicit val timeout = Timeout(10 seconds)

	val timer = actorSystem.actorOf(Props(new TwoStepSimulationTimer), "timer")
	val signalBus = actorSystem.actorOf(Props(new SignalBus(timer)), "signalBus")

	val vehicle = new VehicleFactory(actorSystem, timer, signalBus).createVehicle(VehicleParameters.CompactCar)

	val journey = actorSystem.actorOf(Props(new SignalsJourneyActor(timer, signalBus, simulationParameters.route)), "journey")
	val velocityEstimator = actorSystem.actorOf(Props(new TargetVelocityEstimator(signalBus, journey)))
	val driver = actorSystem.actorOf(Props(new VelocityController(signalBus)))
	val velocityController = actorSystem.actorOf(Props(
		new PIDController("v_diff", "alpha_in",
			simulationParameters.velocityController.proportionalGain, simulationParameters.velocityController.integratorGain,
			simulationParameters.velocityController.differentiatorGain, signalBus)
	))

	val gasPedal = actorSystem.actorOf(Props(new PT1("alpha_in", "alpha", 100, simulationParameters.pedal.gasPedalGain, 0.0, signalBus)))
	val brakePedal = actorSystem.actorOf(Props(new PT1("alpha_in", "beta", 100, simulationParameters.pedal.brakePedalGain, 0.0, signalBus)))
	val brake = actorSystem.actorOf(Props(new Brake("beta", "beta*", 100, signalBus)))

	val signalLogger = actorSystem.actorOf(Props(new SignalLogger(signalBus, result, 50)))

{'fraction_non_alphanumeric': 0.09842906234658812, 'fraction_numerical': 0.017059401080019635, 'mean_word_length': 6.381340579710145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1092718', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2439, 'n_words': 535}