Example #1
0
        /// <summary>
        /// 获取节点合集
        /// </summary>
        /// <param name="chainCode"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <Node> GetNodeList(string chainCode, EnumNodeType type)
        {
            var key = string.Format(CacheKeyFormat, chainCode, type);

            if (CacheManager.TryGet <List <Node> >(key, out var result) && result.Any())
            {
                return(result);
            }
            return(RefreshNodeList(chainCode, type));
        }
Example #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="db"></param>
 /// <param name="key"></param>
 /// <param name="displayText"></param>
 /// <param name="nodeType"></param>
 /// <param name="order"></param>
 public Node(int id, int db, string key,
             string displayText, EnumNodeType nodeType, EnumOrderType order)
 {
     Id          = id;
     Db          = db;
     Key         = key;
     DisplayText = displayText;
     NodeType    = nodeType;
     Order       = order;
 }
Example #3
0
        /// <summary>
        /// 获取节点
        /// </summary>
        /// <param name="type">节点类型</param>
        /// <returns>节点</returns>
        public Node GetNode(string chainCode, EnumNodeType type)
        {
            var endpointList  = GetNodeList(chainCode, type);
            var endpointCount = endpointList.Count;

            var index = _curIndex >= endpointCount ? 0 : _curIndex;

            for (var i = 0; i < endpointCount; i++)
            {
                _node = endpointList[index];

                if (index + 1 >= endpointCount)
                {
                    index = 0;
                }
                else
                {
                    index++;
                }

                if (DelayMap.ContainsKey(_node.HttpAddress))
                {
                    if (DelayMap[_node.HttpAddress] <= DateTime.UtcNow)
                    {
                        DelayMap.TryRemove(_node.HttpAddress, out _);
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            _curIndex = index;
            Console.WriteLine(_node.HttpAddress);

            return(_node);
        }
Example #4
0
        /// <summary>
        /// 刷新节点列表缓存
        /// </summary>
        /// <param name="chainCode"></param>
        /// <param name="type"></param>
        public List <Node> RefreshNodeList(string chainCode, EnumNodeType type)
        {
            var key = string.Format(CacheKeyFormat, chainCode, type);

            var query = DbSet.Where(p => p.ChainCode == chainCode && p.State == (int)EnumState.Normal)
                        .AsQueryable();

            switch (type)
            {
            case EnumNodeType.Player:
                query = query.Where(p => p.PlayerAlternative);
                break;

            case EnumNodeType.Query:
                query = query.Where(p => p.QueryAlternative);
                break;

            case EnumNodeType.Server:
            default:
                query = query.Where(p => p.ServerAlternative);
                break;
            }

            var result = query.OrderByDescending(p => p.Priority).ToList();

            try
            {
                if (result.Any())
                {
                    CacheManager.Set(key, result, 30);
                    CacheManager.Refresh(key);
                }
            }
            catch (Exception)
            {
                // ignored
            }
            return(result);
        }
Example #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="db"></param>
 /// <param name="key"></param>
 /// <param name="displayText"></param>
 /// <param name="nodeType"></param>
 public Node(int id, int db, string key,
             string displayText, EnumNodeType nodeType)
     : this(id, db, key, displayText, nodeType, EnumOrderType.Ascend)
 {
 }
Example #6
0
        public static void EdgeSimulation(FogPost edge, TuplePost tuple, string policy, int CommunicationType, int Service, List <string> DataCenter, string gateway, string cooperation, string edgeType)
        {
            if (cooperation == "0")
            {
                WithCoo = true;
            }
            Random    rnd    = new Random();
            Stopwatch watch  = new Stopwatch();
            var       result = new Results();

            edgeResultList = new List <Results>();
            edgeList       = new List <FogDevice>();
            tupleList      = new List <Models.Tuple>();
            PowerUtility.FillNumRange();
            string JsonReturn, path;

            #region DataSet population
            if (edgeType == "0")
            {
                #region Edge Homogenious

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "EHomo\\JsonEdge.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                edgeList   = JsonConvert.DeserializeObject <List <FogDevice> >(JsonReturn);
                EdgeSize   = edgeList.Count;

                #endregion Edge

                #region Tuple homogenious

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "EHomo\\JsonTuple.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                tupleList  = JsonConvert.DeserializeObject <List <Models.Tuple> >(JsonReturn);

                #endregion Tuple
            }
            else
            {
                #region Edge Hetrogenous

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "EHetro\\JsonEdge.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                edgeList   = JsonConvert.DeserializeObject <List <FogDevice> >(JsonReturn);
                EdgeSize   = edgeList.Count;

                #endregion Edge

                #region Tuple Hetrogenious

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "EHetro\\JsonTuple.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                tupleList  = JsonConvert.DeserializeObject <List <Models.Tuple> >(JsonReturn);
                #endregion Tuple
            }

            #region create fog for Edge-fog cloud
            if (CommunicationType == 1)
            {
                int fCount = Convert.ToInt32(EdgeSize / 2);
                for (int i = 0; i < fCount; i++)
                {
                    bool[] bit = { true };
                    var    b   = rnd.Next(bit.Length);

                    int[] randomRam = { 512, 1024, 2048, 3072, 3584, 4096 };
                    //  var randomRamIndex = rnd.Next(randomRam.Length);
                    var   index           = rnd.Next(randomRam.Length);
                    int[] randomMips      = { 2000, 4000, 8000, 12000, 18000, 20000 };
                    var   randomMipsIndex = rnd.Next(randomMips.Length);

                    int[] randomPe      = { 1, 1, 2, 2, 3, 4 };
                    var   randomPeIndex = rnd.Next(randomPe.Length);

                    int[] randomSize      = { 4000, 5000, 7000, 10000, 12000, 15000 };
                    var   randomSizeIndex = rnd.Next(randomSize.Length);

                    int[] randomDownBW      = { 400, 500, 700, 1000, 1200, 1500 };
                    var   randomDownBWIndex = rnd.Next(randomDownBW.Length);

                    int[] randomUpBW      = { 500, 700, 1000, 1200, 1500, 2000 };
                    var   randomUpBWIndex = rnd.Next(randomUpBW.Length);

                    int[] randomStorage      = { 2500, 4500, 5000, 7000, 10000, 12000 };
                    var   randomStorageIndex = rnd.Next(randomStorage.Length);

                    int[] timeSlice      = { 15, 20, 25, 30 };
                    var   timeSliceIndex = rnd.Next(timeSlice.Length);

                    Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                    EnumNodeType randomDataType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                    fogServers.Add(new FogDevice(
                                       Guid.NewGuid(),
                                       1,
                                       randomMips[index],
                                       randomPe[index],
                                       randomRam[index],
                                       randomUpBW[index],
                                       randomDownBW[index],
                                       randomSize[index],
                                       randomStorage[index],
                                       "fog" + "-" + i,
                                       randomDataType.ToString(),
                                       new CloudletScheduler(),
                                       GeoDistance.RandomGeoLocation(rnd),
                                       bit[b],
                                       0,
                                       PowerUtility.SetIdlePower(),
                                       timeSlice[timeSliceIndex])
                                   );
                }
            }

            #endregion

            #endregion
            SmartThreadPool s = new SmartThreadPool();
            s.MaxThreads = 1000;
            s.MinThreads = 1000;

            List <Task> myTaskList = new List <Task>();
            if (policy == "1")
            {
                //FCFS
                #region P1 FCFS

                s = new SmartThreadPool();
                watch.Start();
                foreach (var item in tupleList)
                {
                    // item.QueueDelay = watch.Elapsed.Milliseconds;
                    // FogUtility.EdgeSim(item, edgeList, CommunicationType);
                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                }
                watch.Stop();
                try
                {
                    s.WaitForIdle();
                    s.Shutdown();
                }
                catch { };
                #endregion
            }
            else if (policy == "2")
            {
                #region P2 SJF
                var localtupleList = tupleList.OrderBy(x => x.MIPS).ToList();

                s = new SmartThreadPool();
                watch.Start();
                foreach (var item in localtupleList)
                {
                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                }
                watch.Stop();
                try
                {
                    s.WaitForIdle();
                    s.Shutdown();
                }
                catch { };
                #endregion
            }
            else if (policy == "3")
            {
                #region P3 LJF
                var localtupleList = tupleList.OrderByDescending(x => x.MIPS).ToList();

                s = new SmartThreadPool();
                watch.Start();
                foreach (var item in localtupleList)
                {
                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                }
                watch.Stop();
                try
                {
                    s.WaitForIdle();
                    s.Shutdown();
                }
                catch { };
                #endregion
            }
            //inserted new policy #change
            //LBFC
            else if (policy == "4")
            {
                try
                {
                    IsCreateCache = true;
                    s             = new SmartThreadPool();
                    ///*getting 5% to inital execute*/
                    double initialRandomTuplesCount = Math.Ceiling((double)((tupleList.Count() * 5) / 100));
                    initial_tupleList = tupleList.Take(Convert.ToInt32(initialRandomTuplesCount)).ToList();
                    final_tupleList   = tupleList.Skip(Convert.ToInt32(initialRandomTuplesCount)).ToList();

                    myTaskList = new List <Task>();
                    var split = LinqExtensions.Split(initial_tupleList, 5).ToList();
                    for (int j = 0; j < split.Count(); j++)
                    {
                        foreach (var item in split[j])
                        {
                            int[] ranIndex       = { 0, 1, 0, 1 };
                            var   randCloudIndex = rnd.Next(ranIndex.Length);

                            watch.Start();

                            if (randCloudIndex == 0)
                            {
                                myTaskList.Add(Task.Factory.StartNew(() =>
                                {
                                    var tupleTime = new TupleTimes()
                                    {
                                        TupleArrival = DateTime.Now.ToString("hh:mm:ss.fff tt"), Name = item.Name
                                    };
                                    lock (Lock)
                                        EdgeSimulator.TupleTimings.Add(tupleTime);
                                    FogUtility.EdgeSim(item, edgeList, CommunicationType);
                                }));
                            }
                            else
                            {
                                myTaskList.Add(Task.Factory.StartNew(() =>
                                {
                                    var tupleTime = new TupleTimes()
                                    {
                                        TupleArrival = DateTime.Now.ToString("hh:mm:ss.fff tt"), Name = item.Name
                                    };
                                    lock (Lock)
                                        FogSimulator.TupleTimings.Add(tupleTime);
                                    FogUtility.FogSimulationForEdge(item, fogServers);
                                }));
                            }
                        }
                    }
                    Task.WaitAll(myTaskList.ToArray());
                    #region threadpool base
                    try
                    {
                        FogCache F_cache, C_cache;
                        ///both are same for edge also
                        foreach (var item in final_tupleList)
                        {
                            lock (Lock)
                            {
                                F_cache = FogUtility.fogCahce.Where(x => x.DataType == item.DataType).OrderBy(x => x.InternalProcessingTime).OrderBy(x => x.link.Propagationtime).FirstOrDefault();
                                C_cache = EdgeCahce.Where(x => x.DataType == item.DataType).OrderBy(x => x.InternalProcessingTime).OrderBy(x => x.link.Propagationtime).FirstOrDefault();
                            }
                            watch.Start();
                            if (F_cache == null || C_cache == null)
                            {
                                int[] ranIndex       = { 0, 1, 0, 1 };
                                var   randCloudIndex = rnd.Next(ranIndex.Length);
                                watch.Start();
                                if (randCloudIndex == 0)
                                {
                                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                                }
                                else
                                {
                                    s.QueueWorkItem(o => FogUtility.FogSimulationForEdge(item, fogServers), new object());
                                }
                            }
                            else
                            {
                                //for predication base
                                double _CTime = C_cache.InternalProcessingTime + C_cache.link.Propagationtime;
                                double _FTime = F_cache.InternalProcessingTime + F_cache.link.Propagationtime;

                                if (_CTime >= _FTime)
                                {
                                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                                }
                                else
                                {
                                    s.QueueWorkItem(o => FogUtility.FogSimulationForEdge(item, fogServers), new object());
                                }
                            }
                        }
                        try
                        {
                            s.WaitForIdle();
                            s.Shutdown();
                        }
                        catch { };
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException(ex.Message);
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Message);
                }
            }
            else
            {
                #region random
                try
                {
                    var split = LinqExtensions.Split(tupleList, 16).ToList();
                    watch.Start();
                    s = new SmartThreadPool();
                    for (int j = 0; j < split.Count(); j++)
                    {
                        foreach (var item in split[j])
                        {
                            s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                        }
                    }

                    try
                    {
                        s.WaitForIdle();
                        s.Shutdown();
                    }
                    catch { };
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                #endregion
            }
            watch.Stop();
            if (policy == "4")
            {
                if (edgeResultList != null)
                {
                    Excel.CreateExcelSheetEdgeFog(edgeResultList, FogTimings.ToList(), TupleTimings.ToList(), DropedtupleList.ToList());
                }
            }
            else

            {
                Excel.CreateExcelSheetEdgeFog(edgeResultList, FogTimings.ToList(), TupleTimings.ToList(), DropedtupleList.ToList());
                if (CommunicationType == 1)
                {
                    Excel.CreateExcelSheetForFog(FogSimulator.resultList, FogSimulator.FogTimings.ToList(), FogSimulator.TupleTimings.ToList());
                }
            }
        }
Example #7
0
        public static void CloudSimulation(TuplePost tuple, string policy, int _service, List <string> datacenter)
        {
            resultList = new ConcurrentBag <Results>();
            Random rnd    = new Random();
            var    result = new Results();

            #region Cloud

            bool[] bit = { true };
            var    b   = rnd.Next(bit.Length);

            // create service
            var service = ServicesUtility.GetServices()[_service];

            #endregion Cloud

            if (FogSimulator.tupleList.Count == 0)
            {
                if (tuple.TupleData.RAM != 0)
                {
                    #region Tuple

                    for (int i = 0; i < tuple.TupleSize; i++)
                    {
                        Array        values         = Enum.GetValues(typeof(EnumDataType));
                        EnumDataType randomDataType = (EnumDataType)values.GetValue(rnd.Next(values.Length));

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomNodeType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        tupleList.Add(new Models.Tuple(
                                          Guid.NewGuid(),
                                          1,
                                          tuple.TupleData.MIPS,
                                          tuple.TupleData.NumberOfPes,
                                          tuple.TupleData.RAM,
                                          tuple.TupleData.BW,
                                          tuple.TupleData.Size,
                                          "T-" + i,
                                          randomDataType.ToString(),
                                          100,
                                          0.0,
                                          "medium",
                                          new CloudletScheduler(),
                                          GeoDistance.RandomGeoLocation(rnd),
                                          false,
                                          randomNodeType.ToString(), 0, 0)
                                      );
                    }

                    #endregion Tuple
                }
                else
                {
                    #region Tuple
                    for (int i = 0; i < tuple.TupleSize; i++)
                    {
                        int[] randomRam      = { 10, 25, 50, 100, 150, 200 };
                        var   randomRamIndex = rnd.Next(randomRam.Length);

                        int[] randomMips      = { 100, 150, 300, 400, 500, 700 };
                        var   randomMipsIndex = rnd.Next(randomMips.Length);

                        int[] randomPe      = { 1 };
                        var   randomPeIndex = rnd.Next(randomPe.Length);

                        int[] randomSize      = { 10, 20, 50, 70, 100 };
                        var   randomSizeIndex = rnd.Next(randomSize.Length);

                        int[] randomBW      = { 10, 30, 50, 80, 100 };
                        var   randomBWIndex = rnd.Next(randomBW.Length);

                        string[] _priority      = { "medium", "low" };
                        var      _priorityIndex = rnd.Next(_priority.Length);

                        Array        values         = Enum.GetValues(typeof(EnumDataType));
                        EnumDataType randomDataType = (EnumDataType)values.GetValue(rnd.Next(values.Length));
                        bool         MedORLB        = randomDataType.ToString() == "Medical" || randomDataType.ToString() == "LocationBased";

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomNodeType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        tupleList.Add(new Models.Tuple(
                                          Guid.NewGuid(),
                                          1,
                                          randomMips[randomMipsIndex],
                                          randomPe[randomPeIndex],
                                          randomRam[randomRamIndex],
                                          randomBW[randomBWIndex],
                                          randomSize[randomSizeIndex],
                                          "T-" + i,
                                          randomDataType.ToString(),
                                          100,
                                          0.0,
                                          MedORLB == true ? "high" : _priority[_priorityIndex],
                                          new CloudletScheduler(),
                                          GeoDistance.RandomGeoLocation(rnd),
                                          false,
                                          randomNodeType.ToString(), 0, 0)
                                      );
                    }

                    #endregion Tuple
                }
            }
            else
            {
                tupleList = FogSimulator.tupleList;
            }
            List <Task> myTaskList = new List <Task>();
            if (policy == "1")
            {
                watch.Start();
                foreach (var item in tupleList)
                {
                    item.QueueDelay = watch.Elapsed.Milliseconds;
                    CloudUtility.CloudSim(item, service, datacenter);
                }
                watch.Stop();
            }
            else if (policy == "2")
            {
                var localtupleList = tupleList.OrderBy(x => x.MIPS).ToList();
                watch.Start();
                foreach (var item in localtupleList)
                {
                    item.QueueDelay = watch.Elapsed.Milliseconds;
                    CloudUtility.CloudSim(item, service, datacenter);
                }
                watch.Stop();
            }
            else if (policy == "3")
            {
                var localtupleList = tupleList.OrderByDescending(x => x.MIPS).ToList();
                watch.Start();
                foreach (var item in localtupleList)
                {
                    item.QueueDelay = watch.Elapsed.Milliseconds;
                    CloudUtility.CloudSim(item, service, datacenter);
                }
                watch.Stop();
            }
            else
            {
                var split = LinqExtensions.Split(tupleList, 16).ToList();
                watch.Start();
                for (int j = 0; j < split.Count(); j++)
                {
                    foreach (var item in split[j])
                    {
                        //commented task section by Ali for testing
                        //myTaskList.Add(Task.Factory.StartNew(() =>
                        //{
                        item.QueueDelay = watch.Elapsed.Milliseconds;
                        CloudUtility.CloudSim(item, service, datacenter);
                        //}));
                    }
                }
                watch.Stop();
                Task.WaitAll(myTaskList.ToArray());
            }
            Excel.CreateExcelSheetForCloud(resultList.ToList());

            resultList = new ConcurrentBag <Results>();
            tupleList  = new List <Models.Tuple>();
        }
Example #8
0
        public IHttpActionResult CreateEdgeDS(FogSimulationPost model)
        {
            try
            {
                /// We are using Same classes in Edge computing
                /// but changing the specifications for Edge..

                Random rnd = new Random();

                FogPost             edge         = model.FogPost;
                Models.TuplePost    tuple        = model.TuplePost;
                bool                F_homo_hetro = true; // true means Homogenious Fogs
                bool                T_homo_hetro = true; // true mean Homogenious  Tuples
                long                EdgeSize     = edge.FogSize;
                List <FogDevice>    edgeList     = new List <FogDevice>();
                List <Models.Tuple> tupleList    = new List <Models.Tuple>();

                #region create Edge dataSet
                if (edge.FogDevice.RAM != 0)
                {
                    #region Edge Homogenious
                    F_homo_hetro = true;
                    for (int i = 0; i < EdgeSize; i++)
                    {
                        bool[] bit = { true, false };
                        var    b   = rnd.Next(bit.Length);

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomDataType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        edgeList.Add(new FogDevice(
                                         Guid.NewGuid(),
                                         1,
                                         edge.FogDevice.MIPS,
                                         edge.FogDevice.NumberOfPes,
                                         edge.FogDevice.RAM,
                                         edge.FogDevice.UpBW,
                                         edge.FogDevice.DownBW,
                                         edge.FogDevice.Size,
                                         edge.FogDevice.Storage,
                                         edge.FogDevice.Name + "-" + i,
                                         randomDataType.ToString(),
                                         new CloudletScheduler(),
                                         GeoDistance.RandomGeoLocation(rnd),
                                         bit[b],
                                         0,
                                         PowerUtility.SetIdlePower(), 15)
                                     );
                    }

                    #endregion Edge
                }
                else
                {
                    #region Edge Hetrogenious
                    F_homo_hetro = false;
                    for (int i = 0; i < EdgeSize; i++)
                    {
                        bool[] bit = { true };
                        var    b   = rnd.Next(bit.Length);

                        int[] randomRam = { 512, 1024, 2048, 3072, 3584, 4096 };
                        //  var randomRamIndex = rnd.Next(randomRam.Length);
                        var   index           = rnd.Next(randomRam.Length);
                        int[] randomMips      = { 2000, 3500, 7000, 10000, 15000, 18000 };
                        var   randomMipsIndex = rnd.Next(randomMips.Length);

                        int[] randomPe      = { 1, 1, 2, 2, 3, 4 };
                        var   randomPeIndex = rnd.Next(randomPe.Length);

                        int[] randomSize      = { 4000, 5000, 7000, 10000, 12000, 15000 };
                        var   randomSizeIndex = rnd.Next(randomSize.Length);

                        int[] randomDownBW      = { 400, 500, 700, 1000, 1200, 1500 };
                        var   randomDownBWIndex = rnd.Next(randomDownBW.Length);

                        int[] randomUpBW      = { 500, 700, 1000, 1200, 1500, 2000 };
                        var   randomUpBWIndex = rnd.Next(randomUpBW.Length);

                        int[] randomStorage      = { 4000, 5000, 7000, 10000, 12000, 15000 };
                        var   randomStorageIndex = rnd.Next(randomStorage.Length);

                        int[] timeSlice      = { 15, 20, 25, 30 };
                        var   timeSliceIndex = rnd.Next(timeSlice.Length);



                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomDataType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        edgeList.Add(new FogDevice(
                                         Guid.NewGuid(),
                                         1,
                                         randomMips[index],
                                         randomPe[index],
                                         randomRam[index],
                                         randomUpBW[index],
                                         randomDownBW[index],
                                         randomSize[index],
                                         randomStorage[index],
                                         edge.FogDevice.Name + "-" + i,
                                         randomDataType.ToString(),
                                         new CloudletScheduler(),
                                         GeoDistance.RandomGeoLocation(rnd),
                                         bit[b],
                                         0,
                                         PowerUtility.SetIdlePower(), timeSlice[timeSliceIndex])
                                     );
                    }
                    // for writing Json file

                    #endregion Fog
                }
                #endregion

                #region Create Tuple data Set

                if (tuple.TupleData.RAM != 0)
                {
                    T_homo_hetro = true;
                    for (int i = 0; i < tuple.TupleSize; i++)
                    {
                        Array            values         = Enum.GetValues(typeof(EnumDataTypeEdge));
                        EnumDataTypeEdge randomDataType = (EnumDataTypeEdge)values.GetValue(rnd.Next(values.Length));

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomNodeType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        tupleList.Add(new Models.Tuple(
                                          Guid.NewGuid(),
                                          1,
                                          tuple.TupleData.MIPS,
                                          tuple.TupleData.NumberOfPes,
                                          tuple.TupleData.RAM,
                                          tuple.TupleData.BW,
                                          tuple.TupleData.Size,
                                          "T-" + i,
                                          randomDataType.ToString(),
                                          100,
                                          0.0,
                                          "medium",
                                          new CloudletScheduler(),
                                          GeoDistance.RandomGeoLocation(rnd),
                                          false,
                                          randomNodeType.ToString(), 20, 0)
                                      );
                    }
                }
                else
                {
                    T_homo_hetro = false;
                    for (int i = 0; i < tuple.TupleSize; i++)
                    {
                        Array            values         = Enum.GetValues(typeof(EnumDataTypeEdge));
                        EnumDataTypeEdge randomDataType = (EnumDataTypeEdge)values.GetValue(rnd.Next(values.Length));
                        bool             MedORLB        = randomDataType.ToString() == "Medical" || randomDataType.ToString() == "LocationBased";

                        var        randomMipsIndex = 0;
                        bool       datatypecheck   = false;
                        List <int> randomMips      = new List <int>();
                        switch (randomDataType.ToString())
                        {
                        //case "Bulk":
                        //    randomMips.Add(500);
                        //    randomMips.Add(700);
                        //    randomMips.Add(900);
                        //    randomMips.Add(1000);
                        //    BulkOrLarge = true;
                        //    randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                        //    break;
                        case "Abrupt":
                            randomMips.Add(350);
                            randomMips.Add(375);
                            randomMips.Add(400);
                            randomMips.Add(450);
                            datatypecheck   = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        case "Large":
                            randomMips.Add(400);
                            randomMips.Add(450);
                            randomMips.Add(500);
                            randomMips.Add(700);
                            datatypecheck   = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        case "Medical":
                            randomMips.Add(250);
                            randomMips.Add(270);
                            randomMips.Add(300);
                            randomMips.Add(350);
                            datatypecheck   = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        case "LocationBased":
                            randomMips.Add(300);
                            randomMips.Add(350);
                            randomMips.Add(375);
                            randomMips.Add(400);
                            datatypecheck   = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        //LocationBased
                        case "Multimedia":
                            randomMips.Add(325);
                            randomMips.Add(350);
                            randomMips.Add(375);
                            randomMips.Add(425);
                            datatypecheck   = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        default:
                            randomMips.Add(75);
                            randomMips.Add(100);
                            randomMips.Add(120);
                            randomMips.Add(150);
                            randomMips.Add(150); randomMips.Add(175);
                            randomMipsIndex = rnd.Next(randomMips.Count);
                            break;
                        }
                        //MB
                        int[] randomRam = { 100, 150, 200, 300, 400, 512 };
                        // var randomRamIndex = rnd.Next(randomRam.Length);
                        var   index         = rnd.Next(randomRam.Length);
                        int[] randomPe      = { 1, 1, 1, 1, 1, 1 };
                        var   randomPeIndex = rnd.Next(randomPe.Length);

                        //MB
                        int[] randomSize      = { 80, 120, 170, 220, 270, 300 };
                        var   randomSizeIndex = rnd.Next(randomSize.Length);

                        //bit/sec
                        int[] randomBW      = { 20, 50, 80, 90, 100, 150 };
                        var   randomBWIndex = rnd.Next(randomBW.Length);

                        string[] _priority      = { "medium", "low" };
                        var      _priorityIndex = rnd.Next(_priority.Length);

                        double[] randomTupleBurstTimes = { 20, 40, 60 };
                        var      randomBusrtIndex      = rnd.Next(randomTupleBurstTimes.Length);


                        var    tupleMips         = datatypecheck == true ? randomMips[randomMipsIndex - 2] : randomMips[randomMipsIndex];
                        double burstTimeForTuple = 0.0;
                        if (tupleMips <= 100)
                        {
                            burstTimeForTuple = 10;
                        }

                        else if (tupleMips > 100 && tupleMips <= 300)
                        {
                            burstTimeForTuple = 15;
                        }

                        else if (tupleMips > 300 && tupleMips < 500)
                        {
                            burstTimeForTuple = 20;
                        }

                        else if (tupleMips > 500 && tupleMips < 700)
                        {
                            burstTimeForTuple = 25;
                        }
                        else if (tupleMips > 700 && tupleMips < 900)
                        {
                            burstTimeForTuple = 30;
                        }

                        else if (tupleMips > 900 && tupleMips <= 1200)
                        {
                            burstTimeForTuple = 35;
                        }
                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomNodeType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));
                        //if(BulkOrLarge) randomMipsIndex
                        tupleList.Add(new Models.Tuple(Guid.NewGuid(),
                                                       1,
                                                       datatypecheck == true ? randomMips[randomMipsIndex - 2] : randomMips[randomMipsIndex],
                                                       randomPe[randomMipsIndex],
                                                       randomRam[randomMipsIndex],
                                                       randomBW[randomMipsIndex],
                                                       randomSize[randomMipsIndex],
                                                       "T-" + i,
                                                       randomDataType.ToString(),
                                                       100,
                                                       0.0,
                                                       MedORLB == true ? "high" : _priority[_priorityIndex],
                                                       new CloudletScheduler(),
                                                       GeoDistance.RandomGeoLocation(rnd),
                                                       false,
                                                       randomNodeType.ToString(), burstTimeForTuple, 0)
                                      );
                    }
                }

                #endregion

                if (edgeList != null && tupleList != null)
                {
                    if (F_homo_hetro)
                    {
                        SimJson.WriteJson(edgeList, "EHomo", "JsonEdge.txt");
                    }
                    else
                    {
                        SimJson.WriteJson(edgeList, "EHetro", "JsonEdge.txt");
                    }
                    if (T_homo_hetro)
                    {
                        SimJson.WriteJson(tupleList, "EHomo", "JsonTuple.txt");
                    }
                    else
                    {
                        SimJson.WriteJson(tupleList, "EHetro", "JsonTuple.txt");
                    }
                }
                return(Ok("ok"));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message.ToString()));
            }
        }
Example #9
0
        public IHttpActionResult createDS(FogSimulationPost model)
        {
            try
            {
                Random rnd = new Random();

                FogPost             fog          = model.FogPost;
                Models.TuplePost    tuple        = model.TuplePost;
                bool                F_homo_hetro = true; //true means Homogenious Fogs
                bool                T_homo_hetro = true; //true mean Homogenious  Tuples
                long                FogSize      = fog.FogSize;
                List <FogDevice>    fogList      = new List <FogDevice>();
                List <Models.Tuple> tupleList    = new List <Models.Tuple>();

                #region create Fog dataSet
                if (fog.FogDevice.RAM != 0)
                {
                    #region Fog
                    F_homo_hetro = true;
                    for (int i = 0; i < FogSize; i++)
                    {
                        bool[] bit = { true, false };
                        var    b   = rnd.Next(bit.Length);

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomDataType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        fogList.Add(new FogDevice(
                                        Guid.NewGuid(),
                                        1,
                                        fog.FogDevice.MIPS,
                                        fog.FogDevice.NumberOfPes,
                                        fog.FogDevice.RAM,
                                        fog.FogDevice.UpBW,
                                        fog.FogDevice.DownBW,
                                        fog.FogDevice.Size,
                                        fog.FogDevice.Storage,
                                        fog.FogDevice.Name + "-" + i,
                                        randomDataType.ToString(),
                                        new CloudletScheduler(),
                                        GeoDistance.RandomGeoLocation(rnd),
                                        bit[b],
                                        0,
                                        PowerUtility.SetIdlePower(), 15)
                                    );
                    }

                    #endregion Fog
                }
                else
                {
                    #region Fog
                    F_homo_hetro = false;
                    for (int i = 0; i < FogSize; i++)
                    {
                        bool[] bit = { true };
                        var    b   = rnd.Next(bit.Length);

                        int[] randomRam = { 4096, 6144, 8192, 10240, 12288, 16384 };
                        //  var randomRamIndex = rnd.Next(randomRam.Length);
                        var index = rnd.Next(randomRam.Length);
                        ///commented original values
                        int[] randomMips = { 25000, 50000, 75000, 85000, 95000, 110000 };

                        //these smaller mips were added by ali for testing
                        //int[] randomMips = { 4000, 5000, 10000, 12000, 15000,3000 };


                        var randomMipsIndex = rnd.Next(randomMips.Length);

                        int[] randomPe      = { 1, 1, 2, 2, 3, 4 };
                        var   randomPeIndex = rnd.Next(randomPe.Length);

                        int[] randomSize      = { 7000, 10000, 12000, 15000, 20000, 25000 };
                        var   randomSizeIndex = rnd.Next(randomSize.Length);

                        int[] randomDownBW      = { 500, 700, 1000, 1200, 1500, 1700 };
                        var   randomDownBWIndex = rnd.Next(randomDownBW.Length);

                        int[] randomUpBW      = { 700, 1000, 1200, 1500, 2000, 2500 };
                        var   randomUpBWIndex = rnd.Next(randomUpBW.Length);

                        int[] randomStorage      = { 5000, 10000, 12000, 15000, 20000, 25000 };
                        var   randomStorageIndex = rnd.Next(randomStorage.Length);

                        //processor burst time is random since it is OS defined and processor defined and it is not calculated
                        int[] timeSlice      = { 15, 20, 25, 30 };
                        var   timeSliceIndex = rnd.Next(timeSlice.Length);

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomDataType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        fogList.Add(new FogDevice(
                                        Guid.NewGuid(),
                                        1,
                                        randomMips[index],
                                        randomPe[index],
                                        randomRam[index],
                                        randomUpBW[index],
                                        randomDownBW[index],
                                        randomSize[index],
                                        randomStorage[index],
                                        fog.FogDevice.Name + "-" + i,
                                        randomDataType.ToString(),
                                        new CloudletScheduler(),
                                        GeoDistance.RandomGeoLocation(rnd),
                                        bit[b],
                                        0,
                                        PowerUtility.SetIdlePower(), timeSlice[timeSliceIndex])
                                    );
                    }
                    // for writing Json file

                    #endregion Fog
                }
                #endregion

                #region Create Tuple data Set

                if (tuple.TupleData.RAM != 0)
                {
                    T_homo_hetro = true;
                    for (int i = 0; i < tuple.TupleSize; i++)
                    {
                        Array        values         = Enum.GetValues(typeof(EnumDataType));
                        EnumDataType randomDataType = (EnumDataType)values.GetValue(rnd.Next(values.Length));

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomNodeType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                        tupleList.Add(new Models.Tuple(
                                          Guid.NewGuid(),
                                          1,
                                          tuple.TupleData.MIPS,
                                          tuple.TupleData.NumberOfPes,
                                          tuple.TupleData.RAM,
                                          tuple.TupleData.BW,
                                          tuple.TupleData.Size,
                                          "T-" + i,
                                          randomDataType.ToString(),
                                          100,
                                          0.0,
                                          "Medium",//its medium temporarly
                                          new CloudletScheduler(),
                                          GeoDistance.RandomGeoLocation(rnd),
                                          false,
                                          randomNodeType.ToString(), 20, 0)
                                      );
                    }
                }
                else
                {
                    T_homo_hetro = false;
                    for (int i = 0; i < tuple.TupleSize; i++)
                    {
                        Array        values          = Enum.GetValues(typeof(EnumDataType));
                        EnumDataType randomDataType  = (EnumDataType)values.GetValue(rnd.Next(values.Length));
                        var          randomMipsIndex = 0;
                        bool         BulkOrLarge     = false;
                        List <int>   randomMips      = new List <int>();
                        bool         MedORLB         = randomDataType.ToString() == "Medical" || randomDataType.ToString() == "LocationBased";
                        switch (randomDataType.ToString())
                        {
                        case "Bulk":
                            randomMips.Add(700);
                            randomMips.Add(900);
                            randomMips.Add(1000);
                            randomMips.Add(1200);
                            BulkOrLarge     = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        case "Large":
                            randomMips.Add(500);
                            randomMips.Add(700);
                            randomMips.Add(900);
                            randomMips.Add(1000);
                            BulkOrLarge     = true;
                            randomMipsIndex = rnd.Next(randomMips.Count) + 2;
                            break;

                        default:
                            randomMips.Add(50);
                            randomMips.Add(75);
                            randomMips.Add(100);
                            randomMips.Add(150);
                            randomMips.Add(200);
                            randomMips.Add(250);

                            randomMipsIndex = rnd.Next(randomMips.Count);
                            break;
                        }
                        //MB
                        int[] randomRam = { 100, 150, 200, 300, 500, 1024 };
                        // var randomRamIndex = rnd.Next(randomRam.Length);
                        var   index         = rnd.Next(randomRam.Length);
                        int[] randomPe      = { 1, 1, 1, 1, 1, 1 };
                        var   randomPeIndex = rnd.Next(randomPe.Length);

                        //MB
                        int[] randomSize      = { 80, 120, 170, 220, 270, 300 };
                        var   randomSizeIndex = rnd.Next(randomSize.Length);

                        //bit/sec
                        int[] randomBW      = { 20, 50, 80, 90, 100, 150 };
                        var   randomBWIndex = rnd.Next(randomBW.Length);

                        string[] _priority      = { "medium", "low" };
                        var      _priorityIndex = rnd.Next(_priority.Length);

                        double[] randomTupleBurstTimes = { 20, 40, 60 };
                        var      randomBusrtIndex      = rnd.Next(randomTupleBurstTimes.Length);

                        Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                        EnumNodeType randomNodeType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));
                        //if(BulkOrLarge) randomMipsIndex

                        var    tupleMips         = BulkOrLarge == true ? randomMips[randomMipsIndex - 2] : randomMips[randomMipsIndex];
                        double burstTimeForTuple = 0.0;
                        if (tupleMips <= 100)
                        {
                            burstTimeForTuple = 10;
                        }

                        else if (tupleMips > 100 && tupleMips <= 300)
                        {
                            burstTimeForTuple = 15;
                        }

                        else if (tupleMips > 300 && tupleMips < 500)
                        {
                            burstTimeForTuple = 20;
                        }

                        else if (tupleMips > 500 && tupleMips < 700)
                        {
                            burstTimeForTuple = 25;
                        }
                        else if (tupleMips > 700 && tupleMips < 900)
                        {
                            burstTimeForTuple = 30;
                        }

                        else if (tupleMips > 900 && tupleMips <= 1200)
                        {
                            burstTimeForTuple = 35;
                        }

                        tupleList.Add(new Models.Tuple(Guid.NewGuid(),
                                                       1,
                                                       BulkOrLarge == true ? randomMips[randomMipsIndex - 2] : randomMips[randomMipsIndex],
                                                       randomPe[randomMipsIndex],
                                                       randomRam[randomMipsIndex],
                                                       randomBW[randomMipsIndex],
                                                       randomSize[randomMipsIndex],
                                                       "T-" + i,
                                                       randomDataType.ToString(),
                                                       100,
                                                       0.0,
                                                       //adding medical, location based and shortest jobs to high priority
                                                       MedORLB == true ? "high" : BulkOrLarge == true?"low":tupleMips <= 100?"high": _priority[_priorityIndex],
                                                       new CloudletScheduler(),
                                                       GeoDistance.RandomGeoLocation(rnd),
                                                       false,
                                                       randomNodeType.ToString(), burstTimeForTuple, 0)
                                      );
                    }
                }

                #endregion

                if (fogList != null && tupleList != null)
                {
                    if (F_homo_hetro)
                    {
                        SimJson.WriteJson(fogList, "H**o", "JsonFog.txt");
                    }
                    else
                    {
                        SimJson.WriteJson(fogList, "Hetro", "JsonFog.txt");
                    }
                    if (T_homo_hetro)
                    {
                        SimJson.WriteJson(tupleList, "H**o", "JsonTuple.txt");
                    }
                    else
                    {
                        SimJson.WriteJson(tupleList, "Hetro", "JsonTuple.txt");
                    }
                }
                return(Ok("ok"));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message.ToString()));
            }
        }
Example #10
0
 public AbstractByamlNode(EnumNodeType identifier, T value, String name)
 {
     NodeIdentifier = identifier;
     Value          = value;
     NodeName       = name;
 }
Example #11
0
        public static void MPRSimulation(FogPost edge, TuplePost tuple, string policy, int CommunicationType, int Service, List <string> DataCenter, string gateway, string cooperation, string edgeType)
        {
            Random    rnd    = new Random();
            Stopwatch watch  = new Stopwatch();
            var       result = new Results();

            edgeResultList = new List <Results>();
            edgeList       = new List <FogDevice>();
            tupleList      = new List <Models.Tuple>();
            PowerUtility.FillNumRange();
            string JsonReturn, path;

            #region DataSet reading
            if (edgeType == "0")
            {
                #region Memory Homogenious

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "H**o\\JsonFog.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                edgeList   = JsonConvert.DeserializeObject <List <FogDevice> >(JsonReturn);
                EdgeSize   = edgeList.Count;

                #endregion

                #region Tuple homogenious

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "H**o\\JsonTuple.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                tupleList  = JsonConvert.DeserializeObject <List <Models.Tuple> >(JsonReturn);

                #endregion Tuple
            }
            else
            {
                #region Memory Hetrogenous

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "Hetro\\JsonFog.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                edgeList   = JsonConvert.DeserializeObject <List <FogDevice> >(JsonReturn);
                EdgeSize   = edgeList.Count;

                #endregion

                #region Tuple Hetrogenious

                path       = (new FileInfo(Path.Combine(FileInformation.GetDirectory(), "Hetro\\JsonTuple.txt"))).ToString();
                JsonReturn = SimJson.ReadJsonFile(path);
                tupleList  = JsonConvert.DeserializeObject <List <Models.Tuple> >(JsonReturn);
                #endregion Tuple
            }

            #region create fog for Edge-fog cloud
            if (CommunicationType == 1)
            {
                int fCount = Convert.ToInt32(EdgeSize / 2);
                for (int i = 0; i < fCount; i++)
                {
                    bool[] bit = { true };
                    var    b   = rnd.Next(bit.Length);

                    int[] randomRam = { 512, 1024, 2048, 3072, 3584, 4096 };
                    //  var randomRamIndex = rnd.Next(randomRam.Length);
                    var   index           = rnd.Next(randomRam.Length);
                    int[] randomMips      = { 2000, 4000, 8000, 12000, 18000, 20000 };
                    var   randomMipsIndex = rnd.Next(randomMips.Length);

                    int[] randomPe      = { 1, 1, 2, 2, 3, 4 };
                    var   randomPeIndex = rnd.Next(randomPe.Length);

                    int[] randomSize      = { 4000, 5000, 7000, 10000, 12000, 15000 };
                    var   randomSizeIndex = rnd.Next(randomSize.Length);

                    int[] randomDownBW      = { 400, 500, 700, 1000, 1200, 1500 };
                    var   randomDownBWIndex = rnd.Next(randomDownBW.Length);

                    int[] randomUpBW      = { 500, 700, 1000, 1200, 1500, 2000 };
                    var   randomUpBWIndex = rnd.Next(randomUpBW.Length);

                    int[] randomStorage      = { 2500, 4500, 5000, 7000, 10000, 12000 };
                    var   randomStorageIndex = rnd.Next(randomStorage.Length);

                    Array        NodeTypevalues = Enum.GetValues(typeof(EnumNodeType));
                    EnumNodeType randomDataType = (EnumNodeType)NodeTypevalues.GetValue(rnd.Next(NodeTypevalues.Length));

                    fogServers.Add(new FogDevice(
                                       Guid.NewGuid(),
                                       1,
                                       randomMips[index],
                                       randomPe[index],
                                       randomRam[index],
                                       randomUpBW[index],
                                       randomDownBW[index],
                                       randomSize[index],
                                       randomStorage[index],
                                       "fog" + "-" + i,
                                       randomDataType.ToString(),
                                       new CloudletScheduler(),
                                       GeoDistance.RandomGeoLocation(rnd),
                                       bit[b],
                                       0,
                                       PowerUtility.SetIdlePower())
                                   );
                }
            }

            #endregion

            #endregion
            SmartThreadPool s = new SmartThreadPool();
            s.MaxThreads = 1000;
            s.MinThreads = 1000;

            List <Task> myTaskList = new List <Task>();
            if (policy == "1")
            {
                //FCFS
                #region P1 FCFS

                s = new SmartThreadPool();
                watch.Start();
                foreach (var item in tupleList)
                {
                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                }
                watch.Stop();
                try
                {
                    s.WaitForIdle();
                    s.Shutdown();
                }
                catch { };
                #endregion
            }
            else if (policy == "2")
            {
                #region P2 SJF
                var localtupleList = tupleList.OrderBy(x => x.MIPS).ToList();

                s = new SmartThreadPool();
                watch.Start();
                foreach (var item in localtupleList)
                {
                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                }
                watch.Stop();
                try
                {
                    s.WaitForIdle();
                    s.Shutdown();
                }
                catch { };
                #endregion
            }
            else if (policy == "3")
            {
                #region P3 LJF
                var localtupleList = tupleList.OrderByDescending(x => x.MIPS).ToList();

                s = new SmartThreadPool();
                watch.Start();
                foreach (var item in localtupleList)
                {
                    s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                }
                watch.Stop();
                try
                {
                    s.WaitForIdle();
                    s.Shutdown();
                }
                catch { };
                #endregion
            }
            else
            {
                #region random
                try
                {
                    var split = LinqExtensions.Split(tupleList, 16).ToList();
                    watch.Start();
                    s = new SmartThreadPool();
                    for (int j = 0; j < split.Count(); j++)
                    {
                        foreach (var item in split[j])
                        {
                            s.QueueWorkItem(o => FogUtility.EdgeSim(item, edgeList, CommunicationType), new object());
                        }
                    }
                    try
                    {
                        s.WaitForIdle();
                        s.Shutdown();
                    }
                    catch { };
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                #endregion
            }
            watch.Stop();
            if (policy == "4")
            {
                if (edgeResultList != null)
                {
                    Excel.CreateExcelSheetEdgeFog(edgeResultList, FogTimings.ToList(), TupleTimings.ToList(), DropedtupleList.ToList());
                }
            }
            else

            {
                Excel.CreateExcelSheetEdgeFog(edgeResultList, FogTimings.ToList(), TupleTimings.ToList(), DropedtupleList.ToList());
                if (CommunicationType == 1)
                {
                    Excel.CreateExcelSheetForFog(FogSimulator.resultList, FogSimulator.FogTimings.ToList(), FogSimulator.TupleTimings.ToList());
                }
            }
        }
Example #12
0
        public static void CreateNode(EngineGraph currentGraph, EnumNodeType nodeType, Vector2 mousePos)
        {
            if (currentGraph != null)
            {
                NTemplate currentNode = null;
                switch (nodeType)
                {
                case EnumNodeType.Text:
                    currentNode          = (NText)ScriptableObject.CreateInstance <NText>();
                    currentNode.nodeName = "Text State";
                    break;

                case EnumNodeType.Branch_Condition:
                    currentNode          = (NConditionalBranch)ScriptableObject.CreateInstance <NConditionalBranch>();
                    currentNode.nodeName = "Conditional Branch State";
                    break;

                case EnumNodeType.Condition:
                    currentNode          = (NCondition)ScriptableObject.CreateInstance <NCondition>();
                    currentNode.nodeName = "Condition State";
                    break;

                case EnumNodeType.Branch_Question:
                    currentNode          = (NQuestionBranch)ScriptableObject.CreateInstance <NQuestionBranch>();
                    currentNode.nodeName = "Question Branch State";
                    break;

                case EnumNodeType.Answer:
                    currentNode          = (NAnswer)ScriptableObject.CreateInstance <NAnswer>();
                    currentNode.nodeName = "Answer State";
                    break;

                case EnumNodeType.Delay:
                    currentNode          = (NDelay)ScriptableObject.CreateInstance <NDelay>();
                    currentNode.nodeName = "Delay State";
                    break;

                case EnumNodeType.Start:
                    currentNode          = (NStart)ScriptableObject.CreateInstance <NStart>();
                    currentNode.nodeName = "Start State";
                    break;

                case EnumNodeType.End:
                    currentNode          = (NEnd)ScriptableObject.CreateInstance <NEnd>();
                    currentNode.nodeName = "End State";
                    break;

                case EnumNodeType.Clear:
                    currentNode          = (NClearText)ScriptableObject.CreateInstance <NClearText>();
                    currentNode.nodeName = "Clear Text State";
                    break;

                case EnumNodeType.Change_Flow_Chart:
                    currentNode          = (NChangeFlowChart)ScriptableObject.CreateInstance <NChangeFlowChart>();
                    currentNode.nodeName = "Change Flow Chart State";
                    break;

                case EnumNodeType.Set_Param:
                    currentNode          = (NSetParam)ScriptableObject.CreateInstance <NSetParam>();
                    currentNode.nodeName = "Set Parameter State";
                    break;

                case EnumNodeType.Play_Music:
                    currentNode          = (NPlayMusic)ScriptableObject.CreateInstance <NPlayMusic>();
                    currentNode.nodeName = "Play Music State";
                    break;

                case EnumNodeType.Stop_Music:
                    currentNode          = (NStopMusic)ScriptableObject.CreateInstance <NStopMusic>();
                    currentNode.nodeName = "Stop Music State";
                    break;

                case EnumNodeType.Play_Sound:
                    currentNode          = (NPlaySound)ScriptableObject.CreateInstance <NPlaySound>();
                    currentNode.nodeName = "Play Sound FX State";
                    break;

                case EnumNodeType.Stop_Sound:
                    currentNode          = (NStopSound)ScriptableObject.CreateInstance <NStopSound>();
                    currentNode.nodeName = "Stop Sound FX State";
                    break;

                case EnumNodeType.Play_Voice:
                    currentNode          = (NPlayVoice)ScriptableObject.CreateInstance <NPlayVoice>();
                    currentNode.nodeName = "Play Voice State";
                    break;

                case EnumNodeType.Stop_Voice:
                    currentNode          = (NStopVoice)ScriptableObject.CreateInstance <NStopVoice>();
                    currentNode.nodeName = "Stop Voice State";
                    break;

                case EnumNodeType.Hide_Text_Container:
                    currentNode          = (NHideTextContainer)ScriptableObject.CreateInstance <NHideTextContainer>();
                    currentNode.nodeName = "Hide Text Container State";
                    break;

                case EnumNodeType.Show_Text_Container:
                    currentNode          = (NShowTextContainer)ScriptableObject.CreateInstance <NShowTextContainer>();
                    currentNode.nodeName = "Show Text Container State";
                    break;

                case EnumNodeType.Change_Background:
                    currentNode          = (NChangeBackground)ScriptableObject.CreateInstance <NChangeBackground>();
                    currentNode.nodeName = "Change Background State";
                    break;

                case EnumNodeType.Show_Character:
                    currentNode          = (NShowCharacter)ScriptableObject.CreateInstance <NShowCharacter>();
                    currentNode.nodeName = "Show Character State";
                    break;

                case EnumNodeType.Hide_Character:
                    currentNode          = (NHideCharacter)ScriptableObject.CreateInstance <NHideCharacter>();
                    currentNode.nodeName = "Hide Character State";
                    break;

                case EnumNodeType.Change_Character_Sprite:
                    currentNode          = (NChangeCharacterSprite)ScriptableObject.CreateInstance <NChangeCharacterSprite>();
                    currentNode.nodeName = "Change Character Sprite State";
                    break;

                case EnumNodeType.Move_Character:
                    currentNode          = (NMoveCharacter)ScriptableObject.CreateInstance <NMoveCharacter>();
                    currentNode.nodeName = "Move Character State";
                    break;

                case EnumNodeType.Trigger_Event:
                    currentNode          = (NTriggerEvent)ScriptableObject.CreateInstance <NTriggerEvent>();
                    currentNode.nodeName = "Trigger Event State";
                    break;
                }

                if (currentNode != null)
                {
                    currentNode.name = currentNode.nodeName;
                    currentNode.InitNode();
                    currentNode.myRect.x    = mousePos.x;
                    currentNode.myRect.y    = mousePos.y;
                    currentNode.parentGraph = currentGraph;
                    currentGraph.nodes.Add(currentNode);

                    if (currentGraph.wantsConnection)
                    {
                        currentNode.CallConnection();
                    }

                    AssetDatabase.AddObjectToAsset(currentNode, currentGraph);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
        }
Example #13
0
        /// <summary>
        /// 获取节点合集
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <Node> GetNodeList(string chainCode, EnumNodeType type)
        {
            var list = Repository.GetNodeList(chainCode, type);

            return(list);
        }
Example #14
0
        /// <summary>
        /// 获取节点
        /// </summary>
        /// <param name="chainCode"></param>
        /// <param name="type">节点类型</param>
        /// <returns>节点</returns>
        public Node GetNode(string chainCode, EnumNodeType type)
        {
            var list = Repository.GetNode(chainCode, type);

            return(list);
        }