public void LoadAllHCP() { var tspLib = new TspLib95(RootDir); tspLib.LoadAllHCP(); var items = tspLib.HCPItems(); Assert.AreEqual(Enumerable.Count(items), 9); }
private static double TspCanonicalDistance(string problemName, int nrNodes) { var tspLib = new TspLib95(RootDir); tspLib.LoadTSP(problemName); var problem = tspLib.GetItemByName(problemName, ProblemType.TSP).Problem; var nodes = Enumerable.Range(1, nrNodes); var tour = new Tour(problemName, "", nodes.Count(), nodes); return problem.TourDistance(tour); }
public void LoadNone() { var tspLib = new TspLib95(RootDir); Assert.IsFalse(tspLib.Items.Any()); Assert.IsFalse(tspLib.ATSPItems().Any()); Assert.IsFalse(tspLib.TSPItems().Any()); Assert.IsFalse(tspLib.SOPItems().Any()); Assert.IsFalse(tspLib.HCPItems().Any()); Assert.IsFalse(tspLib.CVRPItems().Any()); }
public void CtorGivenItemThatDoesNotHave2DNodesShouldThrowArgumentOutOfRangeException(string tspProblemName) { // arrange var tspLib = new TspLib95(Helpers.LibPath); tspLib.LoadTSP(tspProblemName); var items = tspLib.TSPItems(); // assert // ReSharper disable once ObjectCreationAsStatement Assert.Throws<ArgumentOutOfRangeException>(() => new SymmetricTspItemInfoProvider(items.First())); }
/// <summary> /// Constructor. /// </summary> /// <param name="tspLibPath">The directory path to the TSPLIB95 library.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown if no TspLib95Items were loaded.</exception> public SymmetricTspItemLoader(string tspLibPath) { try { var tspLib = new TspLib95(tspLibPath); var items = tspLib.LoadAllTSP(); const int maxNodes = 100; var nodeType = typeof(Node2D); _tspLibItems = (from i in items let nodes = i.Problem.NodeProvider.GetNodes() where nodes.Count <= maxNodes where nodes.All(n => n.GetType() == nodeType) select i).ToList(); ProblemNames = _tspLibItems.Select(i => i.Problem.Name).ToList(); } catch (Exception e) { throw new ArgumentOutOfRangeException($"No TspLib95Items were loaded for path: '{tspLibPath}'", e); } }
public void LoadByNameNullDir() { var tspLib = new TspLib95(RootDir); tspLib.LoadTSP(""); }
public void LoadWrongTspDir() { var tspLib = new TspLib95(Directory.GetCurrentDirectory()); tspLib.LoadAll(); }
public void TspLibPathInvalidDirectory() { var tspLib = new TspLib95("broken"); }
public void TspLibPathEmpty() { var tspLib = new TspLib95(""); }
public void TspLibPathValid() { var tspLib = new TspLib95(RootDir); Assert.IsNotNull(tspLib); }
public void GetItemByInvalidName() { var tspLib = new TspLib95(RootDir); tspLib.LoadAllTSP(); Assert.IsNull(tspLib.GetItemByName("bob", ProblemType.TSP)); Assert.IsNull(tspLib.GetItemByName("", ProblemType.TSP)); Assert.IsNull(tspLib.GetItemByName(" ", ProblemType.TSP)); }