How to run our code on a Windows machine in Lab E319?
First, connect to the UTEP VPN.
Then, open Remote Desktop Connection (or Microsoft Remote Desktop free from Apple Store if you use Mac), and connect to one of the following computers:
e319-w01.utep.edu
e319-w02.utep.edu
e319-w03.utep.edu
e319-w04.utep.edu
e319-w05.utep.edu
e319-w06.utep.edu
e319-w07.utep.edu
It might pop up a warning sign, but please choose to connect anyway. Then use your UTEP credentials to login.
Great!!! You are now connected to the lab computer. The following operations are all done on the Remote Desktop.
Note: If you connect to one of the computers, I suggest you use this computer all through the semester. If you set everything up on this computer and then connect to another computer, you have to go through all the following steps again to set things up on the other computer.
On the Remote Desktop:
Open the Microsoft Store app, search for Ubuntu 20.04 LTS and install it.
Launch Ubuntu (you could find Ubuntu in the Windows Start Menu), and it will take a few minutes to install.
After Ubuntu is installed, create user name and a password for yourself. Note the user name should only include lower case letters.
Open Ubuntu and type in the following command:
sudo apt-get update
sudo apt-get upgrade
sudo apt install build-essential
If the system asks you Do you want to continue? [Y/n] please press Enter directly without entering anything.
Now, let’s set the environment variables:
Type in the following command and open the .bashrc file:
sudo nano ~/.bashrc
Use the down arrow on your keyboard to go to the bottom of the file, and then add the following three lines to the file:
export GUROBI_HOME="/mnt/c/Linux/gurobi911/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
Then press Ctrl+X, it will ask you whether to save the changes, and you should press Y. Then press Enter to save the file.
Then, restart Ubuntu (close the Ubuntu command window and restart it).
Get a Gurobi academic license (please get a new license because you have to use a separate license from the one that you use on your own computer): End User License Agreement Academic - Gurobi Optimization. You need to get the “Individual Academic License”.
Once you get the license, at the end of the webpage, there is an “Installation” section, and there is a grbgetkey command with your license key.
Then open the Ubuntu command window, ativate your license using the grbgetkey command with your license key provided on the webpage. It will ask you to choose a path for your license file, please hit Enter directly to save your license file at the default location.
Great!!! Now you have set everything up. Next, let’s try to run a sample code.
Copy the following code, and save it as Lecture4.cpp under the Document folder under the Windows system. This folder should be C:\Users\Your_UTEP_Account_Name\Documents (please replace Your_UTEP_Account_Name with your actual UTEP account name, which is the same as the user name for your UTEP email account).
#include "gurobi_c++.h"
#include<iostream>
using namespace std;
int main()
{
GRBEnv env = GRBEnv(); // Set up the Gurobi environment
GRBModel SimpleExample = GRBModel(env); // Define the model as "SimpleExample" - but you could name the model whatever you like
GRBVar P1 = SimpleExample.addVar(0, 60, 20, GRB_CONTINUOUS, "P1"); // Define variable x in the model and its range (0-60)
GRBVar P2 = SimpleExample.addVar(0, 60, 40, GRB_CONTINUOUS, "P2"); // Define variable y in the model and its range (0-60)
SimpleExample.setObjective(20*P1+40*P2, GRB_MINIMIZE); // Define the objective function as to minimize 20P1+40P2
SimpleExample.addConstr(P1 + P2 == 90); // Define the third constraint (P1+P2=90)
SimpleExample.optimize(); // Solve the model
std::cout << "Objective value: " << SimpleExample.get(GRB_DoubleAttr_ObjVal) << endl; // Output the objective value
std::cout << "P1 = " << P1.get(GRB_DoubleAttr_X) << endl; // Output the value of x
std::cout << "P2 = " << P2.get(GRB_DoubleAttr_X) << endl; // Output the value of y
return 0;
}
Then in the Ubuntu command window, type in the following command (again, please replace Your_UTEP_Account_Name with your actual UTEP account name in the following command):
cd /mnt/c/Users/Your_UTEP_Account_Name/Documents
Then type in the following command to compile the C++ code:
g++ -m64 -g -o Lecture4 Lecture4.cpp -I/mnt/c/Linux/gurobi911/linux64/include -L/mnt/c/Linux/gurobi911/linux64/lib -lgurobi_g++5.2 -lgurobi91 -lm
Then use the following command to run your code:
./Lecture4
You should be able to see the solution displayed in the command window after this.






