Exemplo n.º 1
0
        static int ReturnRegionIndexByName(ParsedData _parsedData, string _name)
        {
            for (int i = 0; i < _parsedData.Regions.Count; i++)
            {
                if (_parsedData.Regions[i].Name == _name)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 2
0
        public static int ReturnCountryIndexByName(ParsedData _parsedData, string _name)
        {
            for (int i = 0; i < _parsedData.Countries.Length; i++)
            {
                if (_parsedData.Countries[i] == _name)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 3
0
        static int ReturnProviderIndexByName(ParsedData _parsed, string _name)
        {
            for (int i = 0; i < _parsed.Providers.Length; i++)
            {
                if (_parsed.Providers[i].Name == _name)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 4
0
        public static string[] ParseOutputData(ParsedData _parsedData, List <EvaluatedData> _evaluatedData)
        {
            string[] newProjectLine = new string[_evaluatedData.Count * 3];

            for (int i = 0; i < newProjectLine.Length; i += 3)
            {
                newProjectLine[i]     = ReturnProviderIndexByName(_parsedData, _evaluatedData[i].ProviderName).ToString();
                newProjectLine[i + 1] = ReturnRegionIndexByName(_parsedData, _evaluatedData[i].RegionName).ToString();
                newProjectLine[i + 2] = _evaluatedData[i].Units.ToString();
            }

            return(newProjectLine);
        }
Exemplo n.º 5
0
        static void ParseProjects(ParsedData _data, Project _project, string[] _lineToParse)
        {
            _project.PenaltyValue = Int32.Parse(_lineToParse[0]);
            _project.Country      = _lineToParse[1];

            // new ServicePerUnit
            _project.NeededServices = new ServicePerUnit[_data.Services.Length];
            for (int i = 0; i < _data.Services.Length; i++)
            {
                _project.NeededServices[i]          = new ServicePerUnit();
                _project.NeededServices[i].Service  = _data.Services[i];
                _project.NeededServices[i].Quantity = Int32.Parse(_lineToParse[i + 2]);
            }
        }
Exemplo n.º 6
0
        static int ParseProviders(ParsedData _data, string[][] _arraysToParse, int _currentProviderLine, int _currentProviderIndex)
        {
            _data.Providers[_currentProviderIndex]      = new Provider();
            _data.Providers[_currentProviderIndex].Name = _arraysToParse[_currentProviderLine][0]; // prover name

            int regionCount = Int32.Parse(_arraysToParse[_currentProviderLine][1]);                // numero di regioni

            _data.Providers[_currentProviderIndex].regions = new Region[regionCount];

            // new region
            for (int i = 0; i < regionCount; i++)
            {
                _data.Providers[_currentProviderIndex].regions[i] = new Region();
                ParseRegion(_data, _data.Providers[_currentProviderIndex].regions[i], _arraysToParse, (_currentProviderLine + 1) + (3 * i));
                _data.Regions.Add(_data.Providers[_currentProviderIndex].regions[i]);
            }

            _currentProviderIndex++;

            return(regionCount);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Challenge - Insert File Name With Format :");

            string fileName = Console.ReadLine();
            string path     = EnvironmentPath + "\\" + fileName;;

            string[][] inputText = FileManager.Read(path, ' ');

            ParsedData data = Parser.ParseInputputData(inputText);

            OrderProjectsByPenalty(data);

            Console.WriteLine("Press ESC to terminate.");

            ConsoleKeyInfo pressedKey = Console.ReadKey();

            if (pressedKey.Key == ConsoleKey.Escape)
            {
                return;
            }
        }
Exemplo n.º 8
0
 static void OrderProjectsByPenalty(ParsedData _data)
 {
     _data.ProjectsOrderByPenaltyDescending = _data.ProjectsOrderByInput.OrderByDescending(p => p.PenaltyValue).ToArray();
 }
Exemplo n.º 9
0
        static EvaluatedData SerchBestUnit(ServicePerUnit[] _allocated, ServicePerUnit[] _needed, ParsedData _data, float _actualK, Project project)
        {
            EvaluatedData returnData = new EvaluatedData();

            ServicePerUnit[] actualBestAllocation = new ServicePerUnit[_data.Services.Length];
            float            param = -1;

            foreach (var provider in _data.Providers)
            {
                foreach (var region in provider.regions)
                {
                    for (int i = 0; i < region.Units.Services.Length; i++)
                    {
                        actualBestAllocation[i].Quantity = _allocated[i].Quantity + region.Units.Services[i].Quantity;
                    }

                    float dinstance = 0;

                    for (int i = 0; i < region.Units.Services.Length; i++)
                    {
                        dinstance += (float)Math.Pow((_needed[i].Quantity - actualBestAllocation[i].Quantity), 2);
                    }
                    if (param == -1)
                    {
                        param = dinstance * (float)Math.Pow(region.CostPerUnit, _actualK) * region.RegionLatency[Parser.ReturnCountryIndexByName(_data, project.Country)].LatencyValue;
                    }
                    else
                    {
                        if (param < dinstance * (float)Math.Pow(region.CostPerUnit, _actualK) * region.RegionLatency[Parser.ReturnCountryIndexByName(_data, project.Country)].LatencyValue)
                        {
                            param = dinstance * (float)Math.Pow(region.CostPerUnit, _actualK) * region.RegionLatency[Parser.ReturnCountryIndexByName(_data, project.Country)].LatencyValue;
                        }
                        else
                        {
                            actualBestAllocation    = new ServicePerUnit[_data.Services.Length];
                            returnData.ProviderName = provider.Name;
                            returnData.RegionName   = region.Name;
                        }
                    }
                }
            }
            return(returnData);
        }
Exemplo n.º 10
0
        public static List <EvaluatedData> EvaluateProject(Project _project, int _maxCost, int _minCost, ParsedData _data)
        {
            List <EvaluatedData> returnData = new List <EvaluatedData>();
            float actualK = (float)Math.Pow(_project.PenaltyValue / _minCost, _minCost / _maxCost);

            ServicePerUnit[] allocated;

            foreach (EvaluatedData item in returnData)
            {
                item.Units
            }
        }