public override QAPData ImportData(string path) { var parser = new QAPLIBParser(); parser.Parse(path); var instance = Load(parser); instance.Name = Path.GetFileName(path); instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString(); return(instance); }
public override QAPData LoadData(IDataDescriptor id) { var descriptor = (QAPLIBDataDescriptor)id; var instanceArchiveName = GetResourceName(FileName + @"\.dat\.zip"); using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); using (var stream = entry.Open()) { var parser = new QAPLIBParser(); parser.Parse(stream); var instance = Load(parser); instance.Name = id.Name; instance.Description = id.Description; if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) { var solutionsArchiveName = GetResourceName(FileName + @"\.sln\.zip"); using (var solutionsZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName), ZipArchiveMode.Read)) { entry = solutionsZipFile.GetEntry(descriptor.SolutionIdentifier); using (var solStream = entry.Open()) { var slnParser = new QAPLIBSolutionParser(); slnParser.Parse(solStream, true); if (slnParser.Error != null) { throw slnParser.Error; } int[] assignment = slnParser.Assignment; if (assignment != null && ReversedSolutions.Contains(instance.Name)) { assignment = (int[])slnParser.Assignment.Clone(); for (int i = 0; i < assignment.Length; i++) { assignment[slnParser.Assignment[i]] = i; } } instance.BestKnownAssignment = assignment; instance.BestKnownQuality = slnParser.Quality; } } } return(instance); } } }