public static void SetCrisps() { Crisps crisps = new Crisps(2, 9.9, 1500, "Crisps"); sumOfAllProducts += crisps.Price; crisps.GetInfo(); }
static void Main(string[] args) { /* Följande ordning på upplägget: * 1. Gör en liten meny där man talar om att det finns 3 produkter att välja. * 2. Visa att priset för produkterna är 44 kr för öl, 22 kr för chips och 11 kr för äpple. * 3. Be användaren att mata in pengarna i en money pool, 8 tillgängliga valörer. * 4. Be användaren att välja produkter, och visa samtidigt hur mycket det finns kvar i money poolen efter varje val.. * 5. Visa för användaren en "knapp" för att avsluta köp. * 6. Efter att användaren har beslutat att avsluta sina köp så återbetalas vad som finns kvar i money poolen. * 7. Efter att köpen är avslutade visas en liten meny hue de olika produkterna skall användas. */ Console.Clear(); Products products = new Products(); // Abstract class can not be instantiated by itself Apple apple = new Apple(); Beer beer = new Beer(); Crisps crisps = new Crisps(); Console.WriteLine("You have a wide selection of products to select from the menu:"); Console.WriteLine(); Console.WriteLine($"{apple.size} {apple.measure} {products.product1} from {apple.brand} for {products.price1} {products.currency} "); Console.WriteLine($"{beer.size} {beer.measure} {products.product2} from {beer.brand} for {products.price2} {products.currency} "); Console.WriteLine($"{crisps.size} {crisps.measure} {products.product3} from {crisps.brand} for {products.price3} {products.currency} "); Console.WriteLine(); }
/// <summary> /// Get the candidates of the i. /// get the candidate for the jucntion i. /// An Inter-path is a sequence of road intersections that connect the source to the destination, satisfying two key requirements, shorter routing distances, and higher connectivity. To meet these two requirements, we developed a heuristic function with two probability distributions, the connectivity distribution (denoted by ξ ̃_(i,j)) and the shortest distance distribution (denoted by〖 Φ ̃〗_(i,j)). /// </summary> /// <param name="_i"></param> /// <returns></returns> public CandidateJunction CandidateJunction(Junction _i, Junction _des) { string protocol = Settings.Default.RoutingProtocolString; List <CandidateJunction> candidateJunctions = new List <Routing.CandidateJunction>(); ShortestDistanceSelector computer = new ShortestDistanceSelector(); SegmentConnectivitySelector connect = new SegmentConnectivitySelector(); // values: foreach (Junction _j in _i.Adjacentjunctions) { RoadSegment roadSegment = GetRoadSegment(_i, _j); if (roadSegment != null) { switch (protocol) { case "VEFR": { CandidateJunction can = new CandidateJunction(); can.CurrentJunction = _i; can.NextJunction = _j; can.NextJunction = _j; // CAN id. can.DestinationJunction = _des; can.NextRoadSegment = roadSegment; can.RSSInput = new RSSInput(); // new one. can.RSSInput.DensityCrisp = Settings.Default.WeightConnectivity * Crisps.Density(roadSegment.SegmentLength, roadSegment.VehiclesCount, Settings.Default.CommunicationRange, roadSegment.LanesCount); can.RSSInput.ValidDistanceCrisp = Settings.Default.WeightShortestDistance * Crisps.ValidDistance(_i.CenterLocation, _j.CenterLocation, _des.CenterLocation); can.Priority = RSSRuleBase.Aggregate(can.RSSInput); candidateJunctions.Add(can); if (Settings.Default.SaveJunctionsCrisp) { /// } if (_des.JID == _j.JID) { return(can); } } break; case "HERO": { CandidateJunction can = new Routing.CandidateJunction(); can.CurrentJunction = _i; can.NextJunction = _j; can.NextJunction = _j; // CAN id. can.DestinationJunction = _des; can.NextRoadSegment = roadSegment; // values: //1- shortes distance: can.Perpendiculardistance = computer.Perpendiculardistance(_j.CenterLocation, _i.CenterLocation, _des.CenterLocation); if (_des.JID == _j.JID) { can.AngleDotProdection = 1; } else { computer.AngleDotProdection(_i.CenterLocation, _j.CenterLocation, _des.CenterLocation); } can.Length = computer.Length(_i.CenterLocation, _j.CenterLocation); //-2 connectivity. can.Connectivity = connect.SegmentConnectivity(roadSegment.SegmentLength, roadSegment.VehiclesCount, roadSegment.VehicleInterArrivalMean, Settings.Default.CommunicationRange, roadSegment.LanesCount); candidateJunctions.Add(can); } break; } } } switch (protocol) { case "VEFR": { if (candidateJunctions.Count > 0) { CandidateJunction max = candidateJunctions[0]; for (int j = 1; j < candidateJunctions.Count; j++) { if (candidateJunctions[j].Priority > max.Priority) { max = candidateJunctions[j]; } } return(max); } } break; case "HERO": { // get the max priority. if (candidateJunctions.Count > 0) { CandidateJunction max = candidateJunctions[0]; for (int j = 1; j < candidateJunctions.Count; j++) { if (candidateJunctions[j].HeuristicFunction > max.HeuristicFunction) { max = candidateJunctions[j]; } } return(max); } } break; } return(null); }
private void Combo_crisp_SelectionChanged(object sender, SelectionChangedEventArgs e) { string var = (combo_crisp.SelectedItem as ComboBoxItem).Content.ToString(); if (var == "Density") { } else if (var == "Valid Distance") { List <ValidDistanceRow> List = new List <ValidDistanceRow>(); Point dloc = new Point(100, 100); for (int j = 0; j <= 50; j++) { Point iloc = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100)); Point jloc = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100)); double _Crisp = Crisps.ValidDistance(iloc, jloc, dloc); List.Add(new ValidDistanceRow() { Crisp = _Crisp, ID = j, iloc = iloc, jloc = jloc, dloc = dloc }); } dg.ItemsSource = List; } else if (var == "Transmission Distance") { List <TransmissionDistanceRow> List = new List <TransmissionDistanceRow>(); double comrange = 100; for (int j = 0; j <= 1000; j++) { Point iloc = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100)); Point jloc = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100)); double _Crisp = Crisps.TransmissionDistance(iloc, jloc, comrange); List.Add(new TransmissionDistanceRow() { Crisp = _Crisp, ID = j, iloc = iloc, jloc = jloc }); } dg.ItemsSource = List; } else if (var == "Speed Difference") { List <SpeedDifferenceRow> List = new List <SpeedDifferenceRow>(); double maxSpeed = 100; double si = 5; for (int j = 0; j <= 1000; j++) { double sj = RandomeNumberGenerator.GetUniform(0, 100); double _Crisp = Crisps.SpeedDifference(si, sj, maxSpeed); List.Add(new SpeedDifferenceRow() { ID = j, Si = si, Sj = sj, Crisp = _Crisp }); } dg.ItemsSource = List; } else if (var == "Moving Direction") { List <MovingDirectionRow> List = new List <MovingDirectionRow>(); Point dloc = new Point(100, 100); for (int j = 0; j <= 1000; j++) { Point iloc = new Point(RandomeNumberGenerator.GetUniform(0, 500), RandomeNumberGenerator.GetUniform(0, 500)); Point jloc = new Point(RandomeNumberGenerator.GetUniform(0, 500), RandomeNumberGenerator.GetUniform(0, 500)); double _Crisp = Crisps.MovingDirection(iloc, jloc, dloc); List.Add(new MovingDirectionRow() { Crisp = _Crisp, ID = j, iloc = iloc, jloc = jloc, dloc = dloc }); } dg.ItemsSource = List; } }
/// <summary> /// isRouted= true when both the sender and the dest vechiles are in the same segment. /// </summary> /// <param name="i"></param> /// <param name="MyroadSegment"></param> /// <returns></returns> public CandidateVehicle GetCandidateVehicleUis(VehicleUi i, List <VehicleUi> NodesList, VehicleUi desVehicle, bool isRouted) { string protocol = Settings.Default.RoutingProtocolString; List <CandidateVehicle> candidates = new List <CandidateVehicle>(); List <CandidateVehicle> neighbors = new List <CandidateVehicle>(); double sum = 0; if (NodesList.Count > 0) { foreach (VehicleUi j in NodesList) { if (isRouted) { switch (protocol) { case "VEFR": { // des and sender vehicles both are in the same raod segment. CandidateVehicle jcan = new CandidateVehicle(); jcan.SVID = i.VID; jcan.SelectedVehicle = j; jcan.RVSInput = new RVSInput(); if (Settings.Default.SaveVehiclesCrisp) { jcan.RVSInput.ID = PublicParamerters.sessionID; jcan.RVSInput.DesVehlocation = desVehicle.InstanceLocation; jcan.RVSInput.CurrentVehlocation = i.InstanceLocation; jcan.RVSInput.CandidateVehlocation = j.InstanceLocation; jcan.RVSInput.CurrentVehSpeedInKMH = i.GetSpeedInKMH; jcan.RVSInput.CandidateVehSpeedInKMH = j.GetSpeedInKMH; PublicParamerters.RVSInputList.Add(jcan.RVSInput); // print.. this can be removed } jcan.RVSInput.MovingDirectionCrisp = Crisps.MovingDirection(i.InstanceLocation, j.InstanceLocation, desVehicle.InstanceLocation); jcan.RVSInput.SpeedDifferenceCrisp = Crisps.SpeedDifference(i.GetSpeedInKMH, j.GetSpeedInKMH, Settings.Default.MaxSpeed); // make sure of this i.GetSpeedInKMH jcan.RVSInput.TransmissionDistanceCrisp = Crisps.TransmissionDistance(i.InstanceLocation, j.InstanceLocation, Settings.Default.CommunicationRange); jcan.Priority = jcan.RVSInput.Priority; sum += jcan.Priority; neighbors.Add(jcan); if (j == desVehicle) { return(jcan); } } break; case "HERO": { // des and sender vehicles both are in the same raod segment. CandidateVehicle jcan = new CandidateVehicle(); jcan.SVID = i.VID; jcan.SelectedVehicle = j; jcan.BufferSizeDistribution = BufferSizeDistribution(j.PacketQueue.Count, PublicParamerters.BufferSize); jcan.SignalFadingDistribution = SignalFadingDistribution(Computations.Distance(i.InstanceLocation, j.InstanceLocation), Settings.Default.CommunicationRange); jcan.SpeedDifferenceDistribution = SpeedDifferenceDistribution(i.GetSpeedInKMH, j.GetSpeedInKMH, roadSegment.MaxAllowedSpeed); jcan.MovingDirection = MovingDirectionDis(i.InstanceLocation, j.InstanceLocation, desVehicle.InstanceLocation); sum += jcan.HeursticFunction; neighbors.Add(jcan); if (j == desVehicle) { return(jcan); } } break; } } else { // not in the same segment: switch (protocol) { case "VEFR": { CandidateVehicle jcan = new CandidateVehicle(); jcan.SVID = i.VID; jcan.SelectedVehicle = j; jcan.RVSInput = new RVSInput(); if (Settings.Default.SaveVehiclesCrisp) { jcan.RVSInput.ID = PublicParamerters.sessionID; jcan.RVSInput.DesVehlocation = desVehicle.InstanceLocation; jcan.RVSInput.CurrentVehlocation = i.InstanceLocation; jcan.RVSInput.CandidateVehlocation = j.InstanceLocation; jcan.RVSInput.CurrentVehSpeedInKMH = i.GetSpeedInKMH; jcan.RVSInput.CandidateVehSpeedInKMH = j.GetSpeedInKMH; PublicParamerters.RVSInputList.Add(jcan.RVSInput); // print.. this can be removed } jcan.RVSInput.MovingDirectionCrisp = Crisps.MovingDirection(i.InstanceLocation, j.InstanceLocation, desVehicle.EndJunction.CenterLocation); // make sure of this. // { jcan.RVSInput.SpeedDifferenceCrisp = Crisps.SpeedDifference(i.GetSpeedInKMH, j.GetSpeedInKMH, Settings.Default.MaxSpeed); // make sure of this i.GetSpeedInKMH jcan.RVSInput.TransmissionDistanceCrisp = Crisps.TransmissionDistance(i.InstanceLocation, j.InstanceLocation, Settings.Default.CommunicationRange); jcan.Priority = jcan.RVSInput.Priority; sum += jcan.RVSInput.Priority; neighbors.Add(jcan); } break; case "HERO": { // not in the same segment: CandidateVehicle jcan = new CandidateVehicle(); jcan.SVID = i.VID; jcan.SelectedVehicle = j; jcan.BufferSizeDistribution = BufferSizeDistribution(j.PacketQueue.Count, PublicParamerters.BufferSize); jcan.SignalFadingDistribution = SignalFadingDistribution(Computations.Distance(i.InstanceLocation, j.InstanceLocation), Settings.Default.CommunicationRange); jcan.SpeedDifferenceDistribution = SpeedDifferenceDistribution(i.GetSpeedInKMH, j.GetSpeedInKMH, roadSegment.MaxAllowedSpeed); jcan.MovingDirection = MovingDirectionDis(i.InstanceLocation, j.InstanceLocation, desVehicle.EndJunction.CenterLocation); sum += jcan.HeursticFunction; neighbors.Add(jcan); } break; } } } switch (protocol) { case "VEFR": { if (neighbors.Count > 0) { // get max: CandidateVehicle max = neighbors[0]; if (max != null) { for (int j = 1; j < neighbors.Count; j++) { if (neighbors[j].Priority > max.Priority) { max = neighbors[j]; } } return(max); } } } break; case "HERO": { if (neighbors.Count > 0) { double average = (1 / Convert.ToDouble((neighbors.Count))); double Priority_threshould = average; foreach (CandidateVehicle jcan in neighbors) { double x = jcan.HeursticFunction / sum; jcan.Priority = x; if (jcan.Priority >= Priority_threshould) { candidates.Add(jcan); } } // get max: if (candidates.Count == 0) { return(null); } else if (candidates.Count == 1) { return(candidates[0]); } else { // get max: CandidateVehicle max = candidates[0]; if (max != null) { for (int j = 1; j < candidates.Count; j++) { if (candidates[j].Priority > max.Priority) { max = candidates[j]; } } return(max); } } } } break; } } return(null); }