1 | using System;
|
---|
2 | using System.Text;
|
---|
3 | using HeuristicLab.Problems.QuadraticAssignment;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Services.ProblemInstances.QAPInitializer {
|
---|
6 | class Program {
|
---|
7 | static void Main(string[] args) {
|
---|
8 | QuadraticAssignmentProblem qap = new QuadraticAssignmentProblem();
|
---|
9 | using (ProblemInstancesEntities context = new ProblemInstancesEntities()) {
|
---|
10 | foreach (string instance in qap.EmbeddedInstances) {
|
---|
11 | qap.LoadEmbeddedInstance(instance);
|
---|
12 | // transform matrices into jagged arrays
|
---|
13 | double[][] weights = new double[qap.Weights.Rows][];
|
---|
14 | double[][] distances = new double[qap.Weights.Rows][];
|
---|
15 | for (int i = 0; i < weights.Length; i++) {
|
---|
16 | weights[i] = new double[weights.Length];
|
---|
17 | distances[i] = new double[weights.Length];
|
---|
18 | for (int j = 0; j < weights.Length; j++) {
|
---|
19 | weights[i][j] = qap.Weights[i, j];
|
---|
20 | distances[i][j] = qap.Distances[i, j];
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | QAPInstance dbInstance = context.CreateObject<QAPInstance>();
|
---|
25 | dbInstance.name = qap.Name;
|
---|
26 | dbInstance.description = qap.Description;
|
---|
27 | dbInstance.maximization = qap.Maximization.Value;
|
---|
28 | dbInstance.weights = PrimitiveSerializer.SerializeDoubleMatrix(weights);
|
---|
29 | dbInstance.weights_sha1 = GetSHA1Hash(dbInstance.weights);
|
---|
30 | dbInstance.distances = PrimitiveSerializer.SerializeDoubleMatrix(distances);
|
---|
31 | dbInstance.distances_sha1 = GetSHA1Hash(dbInstance.distances);
|
---|
32 | dbInstance.problemsize = qap.Weights.Rows;
|
---|
33 |
|
---|
34 | context.QAPInstances.AddObject(dbInstance);
|
---|
35 | }
|
---|
36 | context.SaveChanges();
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public static string GetSHA1Hash(string text) {
|
---|
41 | var SHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
|
---|
42 |
|
---|
43 | byte[] arrayData;
|
---|
44 | byte[] arrayResult;
|
---|
45 | string result = null;
|
---|
46 | string temp = null;
|
---|
47 |
|
---|
48 | arrayData = Encoding.ASCII.GetBytes(text);
|
---|
49 | arrayResult = SHA1.ComputeHash(arrayData);
|
---|
50 | for (int i = 0; i < arrayResult.Length; i++) {
|
---|
51 | temp = Convert.ToString(arrayResult[i], 16);
|
---|
52 | if (temp.Length == 1)
|
---|
53 | temp = "0" + temp;
|
---|
54 | result += temp;
|
---|
55 | }
|
---|
56 | return result;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|