New to dotnet? Installation in easy steps
Install dotnet sdk
This step will install the software development kit for dotnet core.
- Enter the dotnet core sdk website: https://www.microsoft.com/net/core
- Choose the right platform on top of the page
- 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:
- Go to https://code.visualstudio.com/
- Choose your platform and download/install VS Code
- Start VS Code
Select Extensions (left on the menu), then enter c# and install the c# package:
Watch the installation at the bottom of the window:
- 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:
- Create a new folder, e.g. optanodemo
- Open your console
- windows: enter cmd in the start field
- linux: enter bash or search for console
- macos: press ctrl + space, enter terminal
Navigate to the new folder optanodemo by typing
cd #folderlocation#/optanodemo
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.
(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:
- Open VS Code (unless it is still open)
- Use open folder (from the file menu or by hitting ctrl-o ctrl-k) and choose the folder optanodemo
Wait a second for VS Code to recognize the folder as a c# project. It should show:
- Confirm to create the required assets with yes.
- Restore the dependencies if requested to do so by yes.
Compile and debug by hitting F5 (or use the menu Debug > Start Debugging) It should show at the bottom of the window:
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); } } } } }
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:
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:
Hit F5 again, when all the code is entered. The application will run and show the gurobi output:
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):
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.