Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2931_OR-Tools_LP_MIP/HeuristicLab.ExtLibs/HeuristicLab.OrTools/6.10.0/HeuristicLab.OrTools-6.10.0/Plugin.cs.frame @ 16373

Last change on this file since 16373 was 16373, checked in by ddorfmei, 5 years ago

#2931:

  • upgraded Google OR-Tools to version 6.10
  • added TextValue and TextValueView to be able to display and edit a multiline string
  • added parameter to set solver specific parameters for supported solvers
  • added support for the Protocol Buffers representation of models (import/export)
  • added import of MPS models
  • added pause/stop functionality to CplexSolver and GlpkSolver
  • refactored wrapper (LinearSolver and related enums)
  • added new algorithm category Exact for LinearProgrammingAlgorithm
File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.IO;
24using System.Linq;
25using System.Runtime.InteropServices;
26using HeuristicLab.PluginInfrastructure;
27
28namespace HeuristicLab.OrTools {
29
30  [Plugin("HeuristicLab.OrTools", "Provides functionality of Google OR-Tools in HeuristicLab. Requires Windows 64-bit", "6.10.0.$WCREV$")]
31  [PluginFile("HeuristicLab.OrTools-6.10.0.dll", PluginFileType.Assembly)]
32  [PluginFile("Google.OrTools.dll", PluginFileType.Assembly)]
33  [PluginFile("Google.OrTools-license.txt", PluginFileType.License)]
34  [PluginFile("Google.OrTools.runtime.win-x64.dll", PluginFileType.NativeDll)]
35  [PluginFile("Google.OrTools_version.txt", PluginFileType.Data)]
36  [PluginFile("Google.Protobuf.dll", PluginFileType.Assembly)]
37  [PluginFile("glpk_4_65.dll", PluginFileType.NativeDll)]
38  [PluginFile("glpk-license.txt", PluginFileType.License)]
39  public class HeuristicLabOrToolsPlugin : PluginBase {
40
41    ~HeuristicLabOrToolsPlugin() {
42      OnUnload(); // HACK: remove once ticket #2961 is resolved
43    }
44
45    public override void OnUnload() {
46      base.OnUnload();
47
48      var dllDir = new FileInfo(GetType().Assembly.Location).Directory;
49      if (dllDir == null)
50        return;
51
52      var nativeDlls = GetType().GetCustomAttributes(typeof(PluginFileAttribute), true)
53        .Cast<PluginFileAttribute>()
54        .Where(pf => pf.FileType == PluginFileType.NativeDll)
55        .Select(pf => pf.FileName);
56
57      foreach (var nativeDll in dllDir.EnumerateFiles().Where(f => nativeDlls.Contains(f.Name))) {
58        var handle = LoadLibrary(nativeDll.FullName);
59        if (handle == IntPtr.Zero)
60          continue;
61
62        FreeLibrary(handle); // close handle obtained above
63        FreeLibrary(handle); // close implicitly obtained handle
64      }
65    }
66
67    [DllImport("kernel32.dll", SetLastError = true)]
68    [return: MarshalAs(UnmanagedType.Bool)]
69    private static extern bool FreeLibrary(IntPtr hModule);
70
71    [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
72    private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
73  }
74}
Note: See TracBrowser for help on using the repository browser.