Using a UTEP ECE Lab Computer for C++ and Gurobi Programming under Linux

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.

How to use a Linux machine in Lab E319 to run our code?

Great News: Our IT administrator has installed Gurobi on all the Linux machines in Lab E319, so we could run our code on these machines as soon as we transfer our code and data input files onto these machines. No need to install WSL, Gurobi, or set environment variables anymore! :tada:

Before we get started, we need to make a small change in our code. If you are using the reusable code (ReusableDCOPF.cpp or LMP.cpp), you need to make a small change in your code to get your code compatible with the environment. You don’t need to make any changes to your code if you are not using a reusable code.

Please open your code, find the line

ifstream DataFile(DataFileLocation); 

and add .c_str() to DataFileLocation in this line, so it becomes :

ifstream DataFile(DataFileLocation.c_str()); 

Then Let’s follow the following steps to run the code on a remote Linux computer.

  1. Use GlobalProtect to connect to the UTEP VPN. Here is a tutorial on how to connect to GlobalProtect if you have never done it before: NET_VPNGlobalProtect

  2. Using Remote Desktop, connect to one of the following Linux machines in the computer lab E319:
    e319-l01.ece.utep.edu
    e319-l02.ece.utep.edu
    e319-l03.ece.utep.edu
    e319-l04.ece.utep.edu
    e319-l05.ece.utep.edu
    e319-l06.ece.utep.edu
    e319-l07.ece.utep.edu
    e319-l08.ece.utep.edu
    e319-l09.ece.utep.edu
    e319-l10.ece.utep.edu
    e319-l11.ece.utep.edu
    e319-l12.ece.utep.edu
    I posted a previous tutorial on how to use Remote Desktop to connect to lab computers here, but it is for the Windows machines: Using a UTEP ECE Lab Computer for C++ and Gurobi Programming under Linux For the Linux machines, all you need to do is to change the address that you connect to – please choose one from the above twelve addresses.

  3. Double-click “Home” on the desktop:

  4. Copy the code and the input data files into the Home folder. In the following picture, I copied LMP.cpp and the SystemData folder into the Home folder:

  5. In the Home folder, right click in an empty space, and choose “Open in Terminal” in the menu:

  6. Then it will open the terminal, and you are right in the Home folder in the terminal (you could see you are in the ~ folder, and that’s the Home folder, where you stored your code and input data files):
    LinuxTutorial4

  7. In the terminal (command window), type in the following command (if you are also trying to run the LMP.cpp code):

g++ -m64 -g -o LMP LMP.cpp -I/opt/gurobi/linux64/include -L/opt/gurobi/linux64/lib -lgurobi_c++ -lgurobi91 -lm

If you want to run another code other than LMP.cpp, all you need to do is to change the file name “LMP.cpp” to whatever file you want to compile, and change “LMP” to whatever output file name that matches with your code. Please only make changes in “LMP LMP.cpp”, and don’t change the rest of the command. There is no need to change the paths after -I and -L, because that’s where Gurobi is installed and we just need to use it as is.

  1. Then type ./LMP in the command window (if your output file name is LMP, as defined in the compiling command), then the code will run and give us the result: