Exemplo n.º 1
0
 public ProductViewModel(ProductModel productModel)
 {
     Id       = productModel.Id;
     Name     = productModel.Name;
     Cost     = productModel.Cost;
     CostType = productModel.CostType;
 }
Exemplo n.º 2
0
        public override void Deserialize(System.IO.BinaryReader r)
        {
            base.Deserialize(r);

            m_NeedVoxel         = r.ReadBoolean();
            m_SkillID           = r.ReadInt32();
            m_CostType          = (ECostType)r.ReadInt32();
            m_ConsumeItem       = r.ReadInt32();
            m_ConsumeCost       = r.ReadInt32();
            m_ConsumeCount      = r.ReadInt32();
            m_ConsumeCountMax   = r.ReadInt32();
            m_ConsumeEnergy     = r.ReadInt32();
            m_ConsumeEnergyCost = r.ReadInt32();
            m_ConsumeEnergyMax  = r.ReadInt32();
        }
Exemplo n.º 3
0
        public void InitNetwork(ECostType costType, CostSettings costSettings, EOptimizerType optimizerType, OptimizerSettings optimizerSettings)
        {
            Utility.Dims InShape;
            Utility.Dims OutShape;
            Utility.Dims WShape;

            for (int i = 1; i < Layers.Count; i++)
            {
                Data.Data["a" + i.ToString()] = new Matrix(Layers[i].NCount, 1);
                InShape = new Utility.Dims(Layers[i].NCount, 1);

                Data.Data["b" + i.ToString()] = Matrix.RandomMatrix(Layers[i].NCount, 1, 1, EDistrubution.Gaussian);

                OutShape = new Utility.Dims(Layers[i].NCount, 1);

                Data.Data["W" + i.ToString()] = Matrix.RandomMatrix(Layers[i - 1].NCount, Layers[i].NCount, 1, EDistrubution.Gaussian);
                WShape = new Utility.Dims(Layers[i - 1].NCount, Layers[i].NCount);

                Layers[i].SetSettings(new LayerSettings(InShape, OutShape, WShape));
            }

            Data.Data["a0"] = new Matrix(Layers[0].NCount, 1);
            InShape         = new Utility.Dims(Layers[0].NCount, 1);

            Data.Data["b0"] = new Matrix(Layers[0].NCount, 1);
            OutShape        = new Utility.Dims(Layers[0].NCount, 1);

            Data.Data["W0"] = new Matrix(Layers[0].NCount * Layers[1].NCount, Layers[1].NCount);
            WShape          = new Utility.Dims(Layers[0].NCount * Layers[1].NCount, Layers[1].NCount);

            Layers[0].SetSettings(new LayerSettings(InShape, OutShape, WShape));

            switch (costType)
            {
            case ECostType.Invalid:
                throw new ArgumentException("Invalid Cost Function Selected!");

            case ECostType.CrossEntropyCost:
                CostFunction = new CrossEntropyCost((CrossEntropyCostSettings)costSettings);
                break;

            case ECostType.ExponentionalCost:
                CostFunction = new ExponentionalCost((ExponentionalCostSettings)costSettings);
                break;

            case ECostType.GeneralizedKullbackLeiblerDivergence:
                CostFunction = new GeneralizedKullbackLeiblerDivergence((GeneralizedKullbackLeiblerDivergenceSettings)costSettings);
                break;

            case ECostType.HellingerDistance:
                CostFunction = new HellingerDistance((HellingerDistanceSettings)costSettings);
                break;

            case ECostType.ItakuraSaitoDistance:
                CostFunction = new ItakuraSaitoDistance((ItakuraSaitoDistanceSettings)costSettings);
                break;

            case ECostType.KullbackLeiblerDivergence:
                CostFunction = new KullbackLeiblerDivergence((KullbackLeiblerDivergenceSettings)costSettings);
                break;

            case ECostType.QuadraticCost:
                CostFunction = new QuadraticCost((QuadraticCostSettings)costSettings);
                break;

            default:
                throw new ArgumentException("Invalid Cost Function Selected!");
            }

            switch (optimizerType)
            {
            case EOptimizerType.Invalid:
                throw new ArgumentException("Invalid Optimizer Function Selected!");

            case EOptimizerType.AdaDelta:
                OptimizerFunction = new AdaDelta((AdaDeltaSettings)optimizerSettings);
                break;

            case EOptimizerType.AdaGrad:
                OptimizerFunction = new AdaGrad((AdaGradSettings)optimizerSettings);
                break;

            case EOptimizerType.Adam:
                OptimizerFunction = new Adam((AdamSettings)optimizerSettings);
                break;

            case EOptimizerType.Adamax:
                OptimizerFunction = new Adamax((AdamaxSettings)optimizerSettings);
                break;

            case EOptimizerType.GradientDescent:
                OptimizerFunction = new GradientDescent((GradientDescentSettings)optimizerSettings);
                break;

            case EOptimizerType.Momentum:
                OptimizerFunction = new Momentum((MomentumSettings)optimizerSettings);
                break;

            case EOptimizerType.Nadam:
                OptimizerFunction = new Nadam((NadamSettings)optimizerSettings);
                break;

            case EOptimizerType.NesterovMomentum:
                OptimizerFunction = new NesterovMomentum((NesterovMomentumSettings)optimizerSettings);
                break;

            case EOptimizerType.RMSProp:
                OptimizerFunction = new RMSProp((RMSPropSettings)optimizerSettings);
                break;

            default:
                throw new ArgumentException("Invalid Optimizer Function Selected!");
            }
        }
Exemplo n.º 4
0
    //@Param startNode: The INodeSearchable object the search should start from.
    //@Param targetNode: The INodeSearchable object the search should be attempting to reach.
    //@Param searchSet: A list containing all nodes to be searched/in the search range.
    public INodeSearchable AStarBasic(INodeSearchable startNode, INodeSearchable targetNode, List <INodeSearchable> searchSet, ECostType costType, EHeuristic heuristic, float dijkstraWeight, float heuristicWeight)
    {
        //A* selects the path that minimizes:
        //f(x) = g(x) + h(x)
        //Where g(x) is the cost of the node, and h(x) is the cost of heursitic

        INodeSearchable currentNode;

        currentNode = startNode;

        foreach (var node in searchSet)
        {
            node.DijkstraCost  = null;
            node.HeuristicCost = null;
            node.TotalCost     = null;
        }
        //Ensures we don't check our starting node twice, and that our starting node is at the front of our "queue"
        searchSet.Remove(currentNode);
        searchSet.Insert(0, currentNode);

        currentNode.DijkstraCost = 0;
        currentNode.TotalCost    = 0;

        while (searchSet.Count > 0)
        {
            currentNode = searchSet[0];
            searchSet.RemoveAt(0);
            searchSet.TrimExcess();

            if (currentNode == targetNode)
            {
                return(targetNode);
            }
            else if (currentNode.DijkstraCost == null)
            {
                //Remaining nodes are assumed unreachable, no path to target, return null as a fail state
                return(null);
            }
            else
            {
                foreach (var child in currentNode.children)
                {
                    if (child == null)
                    {
                        continue;
                    }
                    //Calc the heuristic cost of chosen heuristic measure: h(x)
                    CalculateHeuristic(targetNode, child, heuristic);

                    //Calc the Dijkstra cost of chosen cost measure g(x)
                    CalculateDijkstra(currentNode, child, costType);

                    //Calc the total cost: f(x) = g(x) + h(x)
                    float?total = child.DijkstraCost * dijkstraWeight + child.HeuristicCost * heuristicWeight;



                    if (total < child.TotalCost || child.TotalCost == null)
                    {
                        child.TotalCost = total;
                        child.parent    = currentNode;

                        if (!searchSet.Contains(child))
                        {
                            searchSet.Add(child);
                        }
                    }
                }
            }

            IComparer <INodeSearchable> nullback = new SortNullToBackByTotalCost();
            searchSet.Sort(nullback);
        }

        return(null);
    }
Exemplo n.º 5
0
    //Return: True if cost is reassigned, False if it is not;
    public bool CalculateDijkstra(INodeSearchable currentNode, INodeSearchable child, ECostType costType)
    {
        float?calculatedCost = currentNode.DijkstraCost;

        switch (costType)
        {
        case ECostType.Movement:

            calculatedCost += CalculateMoveCostToReachChildTile(currentNode, child);

            break;

        default:
            break;
        }

        if ((calculatedCost < child.DijkstraCost || child.DijkstraCost == null) && currentNode.parent != child)
        {
            child.DijkstraCost = calculatedCost;
            //child.parent = currentNode;
            return(true);
        }
        return(false);
    }
Exemplo n.º 6
0
    //A Dijkstra Search implementation focused on finding the most efficent way to move to a target tile given the environemental cost to get there.
    INodeSearchable DijkstraSearch(INodeSearchable startNode, INodeSearchable targetNode, List <INodeSearchable> searchSet, ECostType costType)
    {
        INodeSearchable currentNode;

        currentNode = startNode;

        foreach (var node in searchSet)
        {
            node.DijkstraCost = null;
        }
        //Ensures we don't check our starting node twice, and that our starting node is at the front of our "queue"
        searchSet.Remove(currentNode);
        searchSet.Insert(0, currentNode);
        currentNode.DijkstraCost = 0;

        while (searchSet.Count > 0)
        {
            currentNode = searchSet[0];
            searchSet.RemoveAt(0);
            searchSet.TrimExcess();

            if (currentNode == targetNode)
            {
                return(targetNode);
            }
            else if (currentNode.DijkstraCost == null)
            {
                //Remaining nodes are assumed unreachable, no path to target, return null as a fail state
                return(null);
            }
            else
            {
                foreach (var child in currentNode.children)
                {
                    if (child == null)
                    {
                        continue;
                    }
                    bool reassigned = CalculateDijkstra(currentNode, child, costType);
                    if (reassigned)
                    {
                        child.parent = currentNode;
                    }
                    child.TotalCost = child.DijkstraCost;
                }
            }

            IComparer <INodeSearchable> nullback = new SortNullToBackByTotalCost();
            searchSet.Sort(nullback);
        }

        return(null);
    }