using System; using System.Text; using HeuristicLab.Problems.QuadraticAssignment; namespace HeuristicLab.Services.ProblemInstances.QAPInitializer { class Program { static void Main(string[] args) { QuadraticAssignmentProblem qap = new QuadraticAssignmentProblem(); using (ProblemInstancesEntities context = new ProblemInstancesEntities()) { foreach (string instance in qap.EmbeddedInstances) { qap.LoadEmbeddedInstance(instance); // transform matrices into jagged arrays double[][] weights = new double[qap.Weights.Rows][]; double[][] distances = new double[qap.Weights.Rows][]; for (int i = 0; i < weights.Length; i++) { weights[i] = new double[weights.Length]; distances[i] = new double[weights.Length]; for (int j = 0; j < weights.Length; j++) { weights[i][j] = qap.Weights[i, j]; distances[i][j] = qap.Distances[i, j]; } } QAPInstance dbInstance = context.CreateObject(); dbInstance.name = qap.Name; dbInstance.description = qap.Description; dbInstance.maximization = qap.Maximization.Value; dbInstance.weights = PrimitiveSerializer.SerializeDoubleMatrix(weights); dbInstance.weights_sha1 = GetSHA1Hash(dbInstance.weights); dbInstance.distances = PrimitiveSerializer.SerializeDoubleMatrix(distances); dbInstance.distances_sha1 = GetSHA1Hash(dbInstance.distances); dbInstance.problemsize = qap.Weights.Rows; context.QAPInstances.AddObject(dbInstance); } context.SaveChanges(); } } public static string GetSHA1Hash(string text) { var SHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] arrayData; byte[] arrayResult; string result = null; string temp = null; arrayData = Encoding.ASCII.GetBytes(text); arrayResult = SHA1.ComputeHash(arrayData); for (int i = 0; i < arrayResult.Length; i++) { temp = Convert.ToString(arrayResult[i], 16); if (temp.Length == 1) temp = "0" + temp; result += temp; } return result; } } }