public Algorithm(int iterationNumber, int populationCapacity, string filename) { // Initializing of File logging mOutputFileName = filename + "_output.txt"; if (!Directory.Exists("output")) { Directory.CreateDirectory("output"); } sw = new StreamWriter(new FileStream("output/" + mOutputFileName, FileMode.Create, FileAccess.Write)); mFileName = filename; try { mMWrapper = new SalesmanMatrixWrapper(filename + ".txt"); } catch (WrongMatrixException e) { Console.WriteLine(e.Message); mState = AlgorithmState.WrongMatrix; return; } catch (AggregateException ae) { foreach (var e in ae.Flatten().InnerExceptions) { Console.WriteLine(e.Message); } mState = AlgorithmState.WrongMatrix; return; } mLocker = new object(); mCrossMutGate = new AutoResetEvent(false); mRandomizer = new Random(); mIterationNumber = iterationNumber; mPopulationCapacity = populationCapacity; mSelOperator = new RouletteSelection(); mGenOperator = new RouletteGeneration(); // Generating start population: mMainPopulation = mGenOperator.GeneratePop(mMWrapper, mPopulationCapacity); mBufferPopulation = new Person[2 * populationCapacity]; // ... for statistics and something else SetBestPerson(); SetAveFintess(); SetDiversity(); for (int i = 0; i < mCrossRoulette.Length; i++) { mCrossRoulette[i] = mMWrapper.FitnessFunction(mBestPerson); mMutRoulette[i] = mAveFit; } }
public NearestNeighbour(string filename) { try { mMWrapper = new SalesmanMatrixWrapper(filename + ".txt"); } catch (WrongMatrixException e) { Console.WriteLine(e); ok = false; } }