コード例 #1
0
 private double TransportationComparison(Case thisCase, Case otherCase)
 {
     return(_transportSimilarities[thisCase.TransportationIndex, otherCase.TransportationIndex]);
 }
コード例 #2
0
 public CaseComparer(Case inputCase)
 {
     _inputCase   = inputCase;
     _totalWeight = _holidayTypeWeight + _priceWeight + _personNumberWeight
                    + _regionWeight + _transportationWeight + _durationWeight + _seasonWeight + _accommodationWeight;
 }
コード例 #3
0
        private bool TryReadCases(out Case[] caseList)
        {
            var tempCaseList = new List <Case>();

            try
            {
                TextReader textReader = new StreamReader(_inputFile);
                var        csvReader  = new CsvReader(textReader);
                csvReader.Configuration.HasHeaderRecord = false;
                var rowTypeDefinition = new
                {
                    Empty     = string.Empty,
                    FieldName = string.Empty,
                    Value     = string.Empty
                };
                var rows = csvReader.GetRecords(rowTypeDefinition).ToArray();

                var rowIndex = 0;
                while (rowIndex < rows.Length)
                {
                    rowIndex += 3;
                    var curRow      = rows[rowIndex];
                    var journeyCode = int.Parse(CleanString(curRow.Value));
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var holidayType = CleanString(curRow.Value);
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var price = int.Parse(CleanString(curRow.Value));
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var numberOfPeople = int.Parse(CleanString(curRow.Value));
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var region = CleanString(curRow.Value);
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var transportation = CleanString(curRow.Value);
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var duration = int.Parse(CleanString(curRow.Value));
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var season = CleanString(curRow.Value);
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var accommodation = CleanString(curRow.Value);
                    rowIndex++;

                    curRow = rows[rowIndex];
                    var hotel = CleanString(curRow.Value);
                    rowIndex += 4;
                    var curCase = new Case(journeyCode, holidayType, price, numberOfPeople, region, transportation, duration, season, accommodation, hotel);
                    tempCaseList.Add(curCase);
                }
            }
            catch (Exception e)
            {
                caseList = new Case[0];
                return(false);
            }

            caseList = tempCaseList.ToArray();
            return(true);
        }