Esempio n. 1
0
 public virtual void PreVisit(IStateNode state)
 {
     System.Console.WriteLine(currentIndentation
     + "A Drawable of type "
     + state.GetType().ToString()
     + " with name: " + state.Name);
     currentIndentation += indentIncrement;
 }
Esempio n. 2
0
 public void Deserialize()
 {
     nodeData = TypeSerializerHelper.Deserialize(serializeData) as IStateNode;
     if (nodeData == null)
     {
         Debug.LogErrorFormat("反序列化时数据为空 => {0}", serializeData);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// The implementation of Successors for <see cref="IStateSpace"/> . This relies on the
        /// abstract function of this class to generate successor data from the application.
        /// </summary>
        /// <param name="_stateNode">The state node to generate successors for</param>
        /// <returns>An enumeration of successors for the node specified</returns>
        public IEnumerable <IStateNode> Successors(IStateNode _stateNode)
        {
            var node = _stateNode as StateNode ?? throw new ArgumentNullException();

            foreach (var data in Successors(node.Data))
            {
                IStateNode nextNode = GetStateNodeFromData(data);
                yield return(nextNode);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// A state node has not yet been evaluated, so test it using the "current" path and
        /// update its values if its a shorter path
        /// </summary>
        /// <param name="p_current">The node being evaluated</param>
        /// <param name="p_successor">
        /// A successor to that node that needs to be checked for update
        /// </param>
        /// <param name="p_stateSpace">The state space governing the algorithm</param>
        protected virtual void UpdateCell(IStateNode p_current, IStateNode p_successor, IStateSpace p_stateSpace)
        {
            var deltaCost = p_stateSpace.FnCalculateActualCost(p_current, p_successor);

            // If its actually shorter to get to this node from the current node
            if (p_current.ActualCostFromStart + deltaCost < p_successor.ActualCostFromStart)
            {
                // Update the node's information to reflect its new position in the path
                p_successor.ActualCostFromStart = p_current.ActualCostFromStart + deltaCost;
                p_successor.Parent = p_current;

                m_openList.Update(p_successor);   // Will "Add" or "Update" depending on whether or not its in the queue
            }
        }
        protected override float CalculateValue(IStateNode previous, bool newTurnOn)
        {
            if (_turnOnCount > 0)
            {
                return(float.MinValue);  // our task is to turn off server not turn on
            }

            float val = previous.Value;

            val += GetTargetServerResourcesChange().GetValue();

            var change = Changes.Last();

            val += CalculateDiffForUpdatedMachineCase(change.Target.Resources + change.MigrationRequirment);

            return(val);
        }
Esempio n. 6
0
    public StateNode AddNode(IStateNode nodeData, Rect bounds)
    {
        string name = nodeData.GetType().Name;
        DisplayNameAttribute disaplayName = nodeData.GetType().GetCustomAttribute <DisplayNameAttribute>();

        if (disaplayName != null && !string.IsNullOrWhiteSpace(disaplayName.Name))
        {
            name = disaplayName.Name;
        }
        StateNode node = new StateNode
        {
            Bounds = bounds,
            ID     = ++IdIndex,
            Graph  = this,
            Name   = name
        };

        node.SetData(nodeData);
        Nodes.Add(node);
        return(node);
    }
        protected override float CalculateValue(IStateNode previous, bool newTurnOn)
        {
            float val = previous.Value;

            val += GetTargetServerResourcesChange().GetValue();

            var change             = Changes.Last();
            var newServerResources = GetRecieverUsedResources(change.Reciever);

            if (newTurnOn)
            {
                val -= MigrationParams.Current.ServerTurnOnPenalty;
                val += CalculateDiffForNewMachineCase(previous.Value, newServerResources);
            }
            else
            {
                val += CalculateDiffForUpdatedMachineCase(change.Target.Resources);
            }

            return(val);
        }
Esempio n. 8
0
            /// <summary>
            /// Decide if one state node belongs before or after another in the Priority Queue
            /// </summary>
            /// <param name="_other">The other node</param>
            /// <returns></returns>
            public int CompareTo(IStateNode _other)
            {
                if (_other == null)
                {
                    throw new NotSupportedException("Cannot compare an IStateNode to NULL");
                }

                var _ths = this.TotalEstimatedCost;
                var _oth = _other.TotalEstimatedCost;

                if (_ths < _oth)
                {
                    return(-1);
                }
                if (_ths > _oth)
                {
                    return(1);
                }

                return(ActualCostFromStart.CompareTo(_other.ActualCostFromStart));
            }
Esempio n. 9
0
 /// <summary>
 /// Application defined mechanism for determining if a state is the "Goal State".
 /// </summary>
 /// <param name="p_node">The state to check against the "Goal" state</param>
 /// <returns>TRUE if the Goal is equivalent to this node, FALSE if not</returns>
 public abstract bool IsGoalState(IStateNode p_node);
Esempio n. 10
0
 public virtual void PostVisit(IStateNode state)
 {
     currentIndentation = currentIndentation.Substring(0,
         currentIndentation.Length - indentIncrement.Length);
 }
Esempio n. 11
0
 public virtual void PreVisit(IStateNode state)
 {
     System.Console.WriteLine(currentIndentation
     + "Drawable Name: " + state.Name);
     currentIndentation += indentIncrement;
 }
Esempio n. 12
0
 public void OnAfterDeserialize()
 {
     nodeData = null;
     editor   = null;
 }
Esempio n. 13
0
 public void SetData(IStateNode nodeData)
 {
     editor        = null;
     this.nodeData = nodeData;
     OnBeforeSerialize();
 }
 protected abstract float CalculateValue(IStateNode previous, bool newTurnOn);
Esempio n. 15
0
 public void PreVisit(IStateNode state)
 {
     System.Console.WriteLine(currentIndentation + "A State node of type " + state.GetType().ToString() + " with name: " + state.Name);
     currentIndentation += indentIncrement;
 }
Esempio n. 16
0
 public void PostVisit(IStateNode state)
 {
     currentIndentation = currentIndentation.Substring(0, currentIndentation.Length - indentIncrement.Length);
 }