Ejemplo n.º 1
0
 public Example GetExample(string fileName)
 {
     try
     {
         string               buffer;
         string               optCriterion;
         int                  inequalityID = 1;
         List <Equation>      inequalities = new List <Equation>();
         List <double>        targetFunctionCoefficients = null;
         IOptimalityCriterion optimalityCriterion        = null;
         double               freeCoef = 0;
         TargetFunction       targetFunction;
         StreamReader         reader = new StreamReader(fileName);
         while ((buffer = reader.ReadLine()) != null)
         {
             if (buffer == INEQUALITIES_TAG)
             {
                 while ((buffer = reader.ReadLine()) != END_INEQUALITIES_TAG)
                 {
                     if (!string.IsNullOrWhiteSpace(buffer))
                     {
                         inequalities.Add(TranslateStringToEquation(buffer, inequalityID));
                         inequalityID++;
                     }
                 }
             }
             if (buffer == TARGET_FUNCTION_COEFS_TAG)
             {
                 while ((buffer = reader.ReadLine()) != END_TARGET_FUNCTION_COEFS_TAG)
                 {
                     if (!string.IsNullOrWhiteSpace(buffer))
                     {
                         targetFunctionCoefficients = TranslateStringToTargetFunctionCoefficients(buffer);
                     }
                 }
             }
             if (buffer == FREE_COEFFICIENT_TAG)
             {
                 while ((buffer = reader.ReadLine()) != END_FREE_COEFFICIENT_TAG)
                 {
                     if (!string.IsNullOrWhiteSpace(buffer))
                     {
                         freeCoef = Convert.ToDouble(buffer);
                     }
                 }
             }
             if (buffer == OPTIMALITY_CRITERION_TAG)
             {
                 while ((buffer = reader.ReadLine()) != END_OPTIMALITY_CRITERION_TAG)
                 {
                     if (!string.IsNullOrWhiteSpace(buffer))
                     {
                         optCriterion = buffer.ToLower();
                         if (optCriterion == "max")
                         {
                             optimalityCriterion = new MaxOptimalityCriterion();
                         }
                         else if (optCriterion == "min")
                         {
                             optimalityCriterion = new MinOptimalityCriterion();
                         }
                     }
                 }
             }
         }
         reader.Close();
         if (targetFunctionCoefficients == null || optimalityCriterion == null)
         {
             throw new Exception("Отсутствуют необходимые данные и критерии оптимальности или о коэф-ах целевой функции");
         }
         targetFunction = new TargetFunction(targetFunctionCoefficients, optimalityCriterion, freeCoef);
         return(new Example(inequalities, targetFunction));
     }
     catch (Exception e)
     {
         throw new Exception($"Файл {fileName} не существует, либо в нем неверные данные. Конкретная причина - {e.Message}");
     }
 }
Ejemplo n.º 2
0
 public TargetFunction(List <double> coeffiecients, IOptimalityCriterion criterion, double freeCoefficient = default)
 {
     Coefficients        = coeffiecients;
     OptimalityCriterion = criterion;
     FreeCoefficient     = freeCoefficient;
 }
Ejemplo n.º 3
0
 public SimplexMethod(SimplexTable startTable, IOptimalityCriterion optimalityCriterion)
 {
     _table = startTable;
     _optimalityCriterion = optimalityCriterion;
 }