Clingo is an advanced Answer Set Programming (ASP) solver. This guide provides step-by-step instructions on how to install Clingo on a Linux system.
Ensure that your Linux system has the following installed:
build-essential
cmake
re2c
bison
git
If any of these are missing, you can install them using the following command:
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential cmake re2c bison git -y
-
Clone the Clingo Repository:
git clone https://github.com/potassco/clingo.git
-
Navigate to the Clingo Directory:
cd clingo
-
Initialize and Update Submodules:
Clingo comes with submodules which need to be initialized and updated:
git submodule init git submodule update
-
Prepare the Build:
cmake .
-
Build Clingo:
make
-
Test the Installation:
You should now be able to run Clingo from within its directory using the
clingo
command. Try running:./bin/clingo
If the installation was successful, you should see a help message.
After installing Clingo, you can check that it's working correctly by solving N-queens problem.
Here are the steps to create and run the program:
-
Open a text editor and create a new file named
queens.lp
. -
Write the following in the file:
% Define the size of the board #const n = 128. % Define the squares square(1..n, 1..n). % Place a queen on each row 1 { queen(I, J) : square(I, J) } 1 :- I = 1..n. % No two queens on the same row or column :- queen(I, J), queen(K, J), I != K. :- queen(I, J), queen(I, K), J != K. % No two queens on the same diagonal :- queen(I, J), queen(K, L), I-J = K-L, I != K. :- queen(I, J), queen(K, L), I+J = K+L, I != K. % Show the queens #show queen/2.
-
Save and close the file.
-
Open a terminal and navigate to the directory where you saved
queens.lp
. -
Run the program with Clingo using the following command:
./bin/clingo queens.lp
Congratulations, you have successfully run your first ASP program with Clingo!
If you encounter errors during the installation, make sure all the prerequisites are installed and your system is up-to-date. If the errors persist, consider installing a pre-compiled binary of Clingo from the Potassco website.