This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% P 7.3 | |
| % Versao estendida do problema de colorir um mapa. | |
| % Para alem do problema original, apresenta restricoes de exclusao, | |
| % condicoes positivas/negativas, diferencas e preferencias flexiveis. | |
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| %% Base de Factos | |
| paises(5). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Pergunta 3.3 | |
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| objecto(piano, 3, 30). | |
| objecto(cadeira, 1, 10). | |
| objecto(cama, 3, 15). | |
| objecto(mesa, 2, 15). | |
| homens(4). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% P9 | |
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| % numPecas(Id, Min, Max) | |
| numPecas(1, 5, 15). | |
| numPecas(2, 2, 6). | |
| numPecas(3, 5, 10). | |
| numPecas(4, 7, 12). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% P 7.2 | |
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| % docente(Nome, Sexo, Start, End) -> pode dar aulas que comecem de Start a End | |
| docente(pedro, m, 3, 6). | |
| docente(joana, f, 3, 4). | |
| docente(ana, f, 2, 5). | |
| docente(joao, m, 2, 4). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| %% P13 - Prova modelo algures no grupo do fb | |
| % attend(+, -, -) | |
| attend(FilmList, Goings, Worth) :- | |
| length(FilmList, N), | |
| length(Goings, N), | |
| domain(Goings, 0, 1), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| % P 4.a) | |
| table6(L) :- | |
| %% Indices in list L | |
| % Asdrubal=1, Bernardete=2, Cristalinda=3 | |
| % Demetrio=4, Eleuterio=5, Felismina=6 | |
| L = [Asdr, Bern, Crist, Demet, Eleut, Felism], | |
| domain(L, 1, 6), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% Exame PLOG 15-16 | |
| %% P13 | |
| :- use_module(library(lists)). | |
| :- use_module(library(clpfd)). | |
| % concelho(Nome, Distancia, NEleitoresIndecisos) | |
| concelho(x, 120, 410). | |
| concelho(y, 10, 800). | |
| concelho(z, 543, 2387). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Solving Magic Squares using Sicstus PROLOG | |
| :- use_module(library(clpfd)). | |
| :- use_module(library(lists)). | |
| matrixDomain([], _). | |
| matrixDomain([Row | Matrix], N) :- | |
| NSquared is N * N, | |
| length(Row, N), | |
| domain(Row, 1, NSquared), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Solving Magic Squares using Google's ortools | |
| # https://github.com/google/or-tools | |
| from ortools.constraint_solver import pywrapcp | |
| import sys | |
| def main(n=4): | |
| # Create the solver. | |
| solver = pywrapcp.Solver('Magic square') | |
| # declare variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% Code from http://www.emse.fr/~picard/cours/ai/minimax/#sec-3 | |
| % minimax(Pos, BestNextPos, Val) | |
| % Pos is a position, Val is its minimax value. | |
| % Best move from Pos leads to position BestNextPos. | |
| minimax(Pos, BestNextPos, Val) :- % Pos has successors | |
| bagof(NextPos, move(Pos, NextPos), NextPosList), | |
| best(NextPosList, BestNextPos, Val), !. | |
| minimax(Pos, _, Val) :- % Pos has no successors |