예제 #1
0
    public static void ExcludeNode(INode myNode, DetectFailureRequest request)
    {
        ConstellationPlan RecoveryPlan = GenerateConstellation.GenerateTargetConstellation(myNode.Router.ReachableSats(myNode).Count, 7.152f);

        PlanRequest recoveryRequest = new PlanRequest {
            SourceID      = myNode.Id,
            DestinationID = myNode.Id,
            Command       = Request.Commands.GENERATE,
            Plan          = RecoveryPlan,
            Dir           = Router.CommDir.CW
        };

        NetworkUpdateRequest updateRequest = new NetworkUpdateRequest(new List <uint?>()
        {
            request.NodeToCheck
        });

        recoveryRequest.DependencyRequests.Add(updateRequest);

        if (myNode.Router.NextSequential(myNode, Router.CommDir.CW) == null)
        {
            recoveryRequest.Dir = Router.CommDir.CCW;
        }

        PlanGenerator.GeneratePlan(myNode, recoveryRequest);
    }
예제 #2
0
    private void Start()
    {
        RealizedWorldState worldState = new RealizedWorldState();

        RealizedEntity entity = new RealizedEntity();

        entity.Money = 1000;
        worldState.AddEntity(entity);

        // Create Merchant
        Merchant merchant = new Merchant(new Vector2Int(20, 30));

        Item apple = new Item()
        {
            name       = "apple",
            foodAmount = 10
        };
        ItemTemplate appleTemplate = new ItemTemplate(apple);

        merchant.saleEntries.Add(new SaleEntry(appleTemplate, 6));

        Item sword = new Item()
        {
            name       = "sword",
            equippable = true,
            slot       = ItemSlot.Weapon,
            power      = 10
        };
        ItemTemplate swordTemplate = new ItemTemplate(sword);

        merchant.saleEntries.Add(new SaleEntry(swordTemplate, 25));

        worldState.AddMerchant(merchant);

        // Create condition
        //ItemFilter filter = new ItemFilter();
        //filter.minFoodAmount = 1;
        //Condition possessCond = new PossessCondition(entity.Id, filter);
        Condition     powerCond = new PowerCondition(entity.Id, 10);
        ConditionNode topNode   = PlanGenerator.GeneratePlan(powerCond, worldState, 5, 5);

        treeRenderer.RenderTree(topNode);
    }
    public void GenerateTargetConstellation(INode RequesterNode)
    {
        System.Random r = new System.Random(RandomSeed);

        TargetPositions.Clear();

        //If the constellation altitude input from textfield isn't numbers, return
        if (float.TryParse(ConstellationAltitudeInput, out float constellationAltitude) == false)
        {
            return;
        }

        //Set the constellation altitude based on the input textfield
        constellationAltitude = Constants.EarthRadius + Constants.ScaleToSize(constellationAltitude);


        //Get reference to satellites
        Sats = GameObject.FindGameObjectsWithTag("Satellite").ToList();

        List <uint?> reachableNodes = RequesterNode.Router.ReachableSats(RequesterNode).ToList();

        Sats.RemoveAll(sat => reachableNodes.Contains(sat.GetComponent <SatelliteComms>().Node.Id) == false);


        //Remove old location Placeholders
        GameObject.FindGameObjectsWithTag("LocationPlaceholder")?.ToList().ForEach(Destroy);


        for (int i = 0; i < Sats.Count; i++)
        {
            //Create random angle for position of Targetposition
            float angle = (360 / Sats.Count) * i;

            Vector3 instantiationPos = Quaternion.Euler(0, angle, 0) * Vector3.forward;

            //Set it relative to the earth
            Vector3 instantiationVector = (instantiationPos - Vector3.zero).normalized * constellationAltitude;

            //Store for propagation
            TargetPositions.Add(instantiationVector);
            Instantiate(SatLocationPlaceholderPrefab, instantiationVector, Quaternion.identity);
        }

        List <ConstellationPlanEntry> entries = new List <ConstellationPlanEntry>();

        foreach (Vector3 pos in TargetPositions)
        {
            Vector3 position = new Vector3(pos.x, pos.y, pos.z);
            List <ConstellationPlanField> fields = new List <ConstellationPlanField> {
                new ConstellationPlanField("DeltaV", 0, (x, y) => x.CompareTo(y))
            };
            ConstellationPlanEntry entry = new ConstellationPlanEntry(BackendHelpers.NumericsVectorFromUnity(position), fields, (x, y) => 1);
            entries.Add(entry);
        }

        plan = new ConstellationPlan(entries);

        //Send the targetconstellation to random sat
        INode       targetSat = RequesterNode;
        PlanRequest request   = new PlanRequest {
            Command          = Request.Commands.GENERATE,
            SourceID         = targetSat.Id,
            DestinationID    = targetSat.Id,
            SenderID         = 42,
            Dir              = Router.CommDir.CW,
            AckExpected      = true,
            MessageIdentifer = "42",
            Plan             = plan
        };

        PlanGenerator.GeneratePlan(targetSat, request);
    }
예제 #4
0
    public async static void FailureDetected(INode myNode, uint?failedNode)
    {
        //Remove edge from router, ensuring it won't try to route through the failed node
        myNode.Router.DeleteEdge(myNode.Id, failedNode);

        List <uint?> failedNeighbours = new List <uint?>()
        {
            myNode.Id
        };
        List <uint?> neighboursToCheck = myNode.Router.NetworkMap.GetEntryByID(failedNode).Neighbours.Except(failedNeighbours).ToList();

        // Start recovery plan gen without failedNode in case myNode is the only neighbour
        if (neighboursToCheck.Count == 0)
        {
            ConstellationPlan RecoveryPlan = GenerateConstellation.GenerateTargetConstellation(myNode.Router.ReachableSats(myNode).Count, 7.152f);

            PlanRequest recoveryRequest = new PlanRequest {
                SourceID      = myNode.Id,
                DestinationID = myNode.Id,
                Command       = Request.Commands.GENERATE,
                Plan          = RecoveryPlan,
                Dir           = Router.CommDir.CW
            };

            NetworkUpdateRequest updateRequest = new NetworkUpdateRequest(new NetworkUpdateRequest(new List <uint?>()
            {
                failedNode
            }));

            recoveryRequest.DependencyRequests.Add(updateRequest);


            if (myNode.Router.NextSequential(myNode, Router.CommDir.CW) == null)
            {
                recoveryRequest.Dir = Router.CommDir.CCW;
            }

            PlanGenerator.GeneratePlan(myNode, recoveryRequest);
        }
        else     // Otherwise ask another neighbour to try to contact failedNode
        {
            uint?neighbourID = neighboursToCheck[0];
            uint?nextHop     = myNode.Router.NextHop(myNode.Id, neighbourID);

            DetectFailureRequest request = new DetectFailureRequest {
                DestinationID    = neighbourID,
                SourceID         = myNode.Id,
                Command          = Request.Commands.DETECTFAILURE,
                ResponseExpected = false,
                AckExpected      = true,
                NodeToCheck      = failedNode,
                DeadEdges        = new List <Tuple <uint?, uint?> > {
                    new Tuple <uint?, uint?>(myNode.Id, failedNode)
                },
                FailedNeighbours = failedNeighbours
            };

            myNode.Router.NetworkMap.Entries.RemoveAll(entry => entry.ID == failedNode);

            await myNode.CommsModule.SendAsync(nextHop, request, Constants.COMMS_TIMEOUT, Constants.COMMS_ATTEMPTS);
        }
    }
예제 #5
0
파일: Node.cs 프로젝트: kasperhangard/SW-10
    private async void ExecuteRequest(Request request, bool isDependency)
    {
        switch (request.Command)
        {
        case Request.Commands.GENERATE:
            PlanGenerator.GeneratePlan(this, request as PlanRequest);
            break;

        case Request.Commands.EXECUTE:
            PlanExecuter.ExecutePlan(this, request as PlanRequest);
            break;

        case Request.Commands.HEARTBEAT:
            Heartbeat.RespondToHeartbeat(this, request);
            break;

        case Request.Commands.PING:
            Ping.RespondToPing(this, request);
            break;

        case Request.Commands.DETECTFAILURE:
            FailureDetection.DetectFailure(this, request as DetectFailureRequest);
            break;

        case Request.Commands.DISCOVER:

            await Discovery.DiscoverAsync(this, request as DiscoveryRequest);

            break;

        case Request.Commands.POSITION:
            PositionResponse response = new PositionResponse(Id, request.SourceID, Response.ResponseCodes.OK, request.MessageIdentifer, Position);
            CommsModule.Send(request.SourceID, response);
            break;

        case Request.Commands.ADDITION:

            List <uint?>    neighbours = CommsModule.Discover();
            AdditionRequest addition   = (request as AdditionRequest).DeepCopy();

            List <ConstellationPlanField> fields = new List <ConstellationPlanField> {
                new ConstellationPlanField("DeltaV", 0, (x, y) => x.CompareTo(y))
            };
            addition.plan.Entries.Add(new ConstellationPlanEntry(Id, Position, fields, (x, y) => 1));
            ActivePlan = addition.plan;
            Router.UpdateNetworkMap(addition.plan);

            NodeAdditionResponse additionResponse = new NodeAdditionResponse(Id, request.SourceID, Response.ResponseCodes.OK, request.MessageIdentifer, Position, neighbours);
            CommsModule.Send(request.SourceID, additionResponse);
            break;

        case Request.Commands.UPDATENETWORKMAP:
            NetworkUpdateRequest updateRequest = request as NetworkUpdateRequest;

            //Remove any dead nodes from the networkmap
            Router.NetworkMap.Entries.RemoveAll(entry => updateRequest.DeadNodes.Contains(entry.ID));

            //Remove any dead nodes from neighbour lists
            foreach (NetworkMapEntry entry in Router.NetworkMap.Entries)
            {
                foreach (uint?deadNode in updateRequest.DeadNodes)
                {
                    entry.Neighbours.Remove(deadNode);
                }
            }
            break;

        default:
            throw new NotImplementedException(request.Command.ToString() + " was not implemented.");
        }
    }