Show / Hide Table of Contents

    New to dotnet? Installation in easy steps

    Install dotnet sdk

    This step will install the software development kit for dotnet core.

    1. Enter the dotnet core sdk website: https://www.microsoft.com/net/core
    2. Choose the right platform on top of the page
    3. Follow the download and installation procedure for your operating system
      • You may stop before the step Initialize some code

    Install an Integrated Development Environment (IDE)

    There certainly is a bunch of IDEs around, which are great for dotnet development. Most known ones are Visual Studio, Visual Studio Code, IntelliJ IDEA, monodevelop and SharpDevelop. In this example, we will use Visual Studio Code which is free and lightweight:

    1. Go to https://code.visualstudio.com/
    2. Choose your platform and download/install VS Code
    3. Start VS Code
    4. Select Extensions (left on the menu), then enter c# and install the c# package:

      Install C# in VS Code

    5. Watch the installation at the bottom of the window:

      Installing C# in VS Code

    6. Restart VS Code

    Create your first project

    There is many ways to create a dotnet project. Most IDEs use a graphical wizard. Independently of the IDE, the following approach works in any case:

    1. Create a new folder, e.g. optanodemo
    2. Open your console
      • windows: enter cmd in the start field
      • linux: enter bash or search for console
      • macos: press ctrl + space, enter terminal
    3. Navigate to the new folder optanodemo by typing

      cd #folderlocation#/optanodemo
      
    4. Run the following commands to create a new console project and add OPTANO Modeling and the Solver Gurobi to your project:

      dotnet new console
      dotnet add package optano.modeling
      dotnet add package optano.modeling.gurobi
      

      This creates a few files within the folder optanodemo. The file optanodemo.csproj holds the project information, including the reference to the added NuGet packages.

      dotnet new console

      dotnet add package optano.modeling

      (Add package for optano.modeling.gurobi not shown as a screenshot)

    Run your first model using Visual Studio Code

    Now you are ready to enter your first model:

    1. Open VS Code (unless it is still open)
    2. Use open folder (from the file menu or by hitting ctrl-o ctrl-k) and choose the folder optanodemo
      VS Code add assets
    3. Wait a second for VS Code to recognize the folder as a c# project. It should show:

      VS Code add assets

      1. Confirm to create the required assets with yes.
      2. Restore the dependencies if requested to do so by yes.
    4. Compile and debug by hitting F5 (or use the menu Debug > Start Debugging) It should show at the bottom of the window:

      VS Code add assets

    5. Open the file program.cs for the files section on the left hand side and enter some code

      using System.Diagnostics;
      using OPTANO.Modeling.Optimization;
      using OPTANO.Modeling.Optimization.Enums;
      using OPTANO.Modeling.Optimization.Solver.Gurobi75x;
      
      namespace optanodemo
      {
          class Program
          {
              static void Main(string[] args)
              {
                  using (var scope = new ModelScope())
                  {
                      var model = new Model();
                      var x = new Variable("x");
                      var y = new Variable("y");
                      model.AddConstraint(x + y >= 120);
                      model.AddObjective(new Objective(2*x + 3*y));
      
                      using (var solver = new GurobiSolver())
                      {
                          var solution = solver.Solve(model);
                      }
                  }
              }
          }
      }
      
    6. While you enter, some help will show up. Usually some red underlining indicates some issue. When you click on the underlined word, a light bulb on the left hand side should show up:

      VS Code shows an issue

      • The light bulb supports with helpful hints, for example for adding some usings at the top of the file to reference the class Model correctly:

        VS Code use the light bulb

    7. Hit F5 again, when all the code is entered. The application will run and show the gurobi output:

      VS Code shows optimization result

    8. When you add a breakpoint (by click left of a line number, a small red dot will appear), the debugging session will stop at this point. Hovering the cursor on a symbol will show its details. The yellow line will indicate the next step to execute, when you continue (use the player at top of the window):

      VS Code stopped at breakpoint

    Next step(s)

    Create your own Models

    Now you are all set to create your own models!
    Go to Create a Model

    Improve your skills

    Running real-world applications usually requires some more advanced features:

    • Use VariableCollections
    • Configure OPTANO.Modeling
    • Read data from files or databases
    • Visualize data
    • Browse through the Advanced section to learn even more.
    Back to top Copyright © OPTANO GmbH generated with DocFX
    Privacy Policy | Impressum – Legal Notice