針對 .Net 使用 OR-Tools NuGet

簡介

本指南會透過簡單的實際範例,協助您開始使用 .Net 中的 OR-Tools。

雖然這些操作說明可能也適用於其他 Windows 變化版本,但我們僅在符合下列條件的機器上測試這些方法:

Windows 10 64 位元 (x86_64) 內含:

  • Microsoft Visual Studio Enterprise 2022
  • Microsoft Visual Studio Community 2022 Preview 2 以上版本

必備條件

以下各節說明安裝 OR-Tools 的必要條件。

Microsoft Visual C++ 可轉散發

您必須在電腦上安裝 適用於 Visual Studio 2022 的 Microsoft Visual C++ 可轉散發套件 (選取 x64 版本),因為 .Net 的 OR-Tools 程式庫是 C++ 原生程式庫的包裝函式。

.NET Core 3.1 SDK

您必須從以下位置安裝 .NET Core 3.1 SDK 3.1.100 以上版本套件:sdk-3.1.425-windows-x64-installer

.Net 6.0 SDK

您必須從以下位置安裝套件 .NET 6.0 SDK:sdk-6.0.403-windows-x64-installer

取得 .Net 程式碼範例

範例程式碼位於 dotnet_or-tools 存放區。

  1. 將存放區下載為 ZIP 檔案,然後解壓縮或複製存放區:

    git clone -b v9.9 --depth 1 https://github.com/or-tools/dotnet_or-tools
    
  2. 變更為範例目錄:

    cd dotnet_or-tools
    

建構範例

dotnet_or-tools 目錄:

使用以下項目建構專案:

dotnet build -c Release

執行範例

dotnet_or-tools 目錄:

使用以下項目執行二進位檔:

dotnet run -c Release

恭喜!您已使用 OR-Tools 執行應用程式,可以開始使用 OR-Tools 了。