예제 #1
0
        private string GetRandomValue(RlmIO item, RlmIdea idea = null)
        {
            string value = string.Empty;

            // TODO add checking on the types and their max and min values
            switch (item.DotNetType)
            {
            case "System.Boolean":
                int boolMin      = Convert.ToInt32(item.Min);
                int boolMax      = Convert.ToInt32(item.Max + 1);
                int boolIntValue = Util.Randomizer.Next(boolMin, boolMax);
                if (boolIntValue > 1 && boolIntValue < 0)
                {
                    throw new Exception("Boolean value can only be 1 or 0");
                }
                value = Convert.ToBoolean(boolIntValue).ToString();
                break;

            case "System.Double":
            case "System.Decimal":
                double doubleMin = Convert.ToDouble(item.Min);
                double doubleMax = Convert.ToDouble(item.Max);
                value = Util.Randomizer.NextDouble(doubleMin, doubleMax).ToString();
                break;

            default:
                int min = Convert.ToInt32(item.Min);
                int max = Convert.ToInt32(item.Max + 1);
                if (idea != null && idea is RlmOutputLimiter)
                {
                    var itemIdea = idea as RlmOutputLimiter;
                    max = itemIdea.IndexMax + 1;
                    int ideaIndex = Util.Randomizer.Next(min, max);
                    if (itemIdea.GetIndexEquivalent != null)
                    {
                        value = itemIdea.GetIndexEquivalent(ideaIndex).ToString();
                    }
                    else
                    {
                        value = ideaIndex.ToString();
                    }
                }
                else
                {
                    value = Util.Randomizer.Next(min, max).ToString();
                }
                break;
            }

            return(value);
        }
예제 #2
0
        //Process new inputs/outputs during create new network
        private object ProcessNewIO(Rnetwork net, RlmIO io, Boolean ProcessAsOutput = false)
        {
            object            retVal = null;
            Input_Output_Type iot;

            //Create Type
            iot = new Input_Output_Type()
            {
                ID = Util.GenerateHashKey(io.DotNetType), Name = io.DotNetType, DotNetTypeName = io.DotNetType
            };
            if (consoleDisplay)
            {
                Console.WriteLine("Creating new Input_Output_Type: " + io.DotNetType);
            }

            if (!ProcessAsOutput)
            {
                //ToDo: Check for unique names

                //Create Input
                Input newio = new Input()
                {
                    ID = Util.GenerateHashKey(io.Name), Name = io.Name, Rnetwork_ID = net.ID, Input_Output_Type_ID = iot.ID, Input_Output_Type = iot, Min = io.Min, Max = io.Max, Type = io.Type
                };
                io.ID  = newio.ID;
                retVal = newio;
                if (consoleDisplay)
                {
                    Console.WriteLine("Create new Input: " + newio.Name);
                }
            }
            else
            {
                //ToDo: Check for unique names

                //Create Output
                Output newio = new Output()
                {
                    ID = Util.GenerateHashKey(io.Name), Name = io.Name, Rnetwork_ID = net.ID, Input_Output_Type_ID = iot.ID, Input_Output_Type = iot, Min = io.Min, Max = io.Max
                };
                io.ID  = newio.ID;
                retVal = newio;
                if (consoleDisplay)
                {
                    Console.WriteLine("Create new Output: " + newio.Name);
                }
            }

            return(retVal);
        }
        private List <RlmIO> GetRlmIOFromResource(IEnumerable <KeyValuePair <string, Resource> > resourceInputs)
        {
            List <RlmIO> retVal = new List <RlmIO>();

            foreach (var input in resourceInputs)
            {
                Resource res = input.Value;

                RlmIO rlmio = null;
                switch (res.Type)
                {
                case Category.Constant:
                case Category.Variable:

                    rlmio = new RlmIO(res.Name, res.DataType, 0, 0);
                    if (res.RlmInputType != null)
                    {
                        rlmio = new RlmIO(res.Name, res.DataType, 0, 0, res.RlmInputType.Value);
                    }

                    break;

                case Category.Range:

                    rlmio = new RlmIO(res.Name, res.DataType, res.Min, res.Max);
                    if (res.RlmInputType != null)
                    {
                        rlmio = new RlmIO(res.Name, res.DataType, res.Min, res.Max, res.RlmInputType.Value);
                    }

                    break;

                case Category.Data:

                    var data = res.DataObjDictionary;
                    rlmio = new RlmIO(res.Name, res.DataType, 0, data.Count - 1);
                    if (res.RlmInputType != null)
                    {
                        rlmio = new RlmIO(res.Name, res.DataType, 0, data.Count - 1, res.RlmInputType.Value);
                    }

                    break;
                }

                retVal.Add(rlmio);
            }

            return(retVal);
        }