My SWI-Prolog page
This page is maintained by Hakan Kjellerstrand (hakank@gmail.com)
SWI-Prolog is a popular Prolog system which has support for CLPFD and many other features.
Some useful pages for SWI-Prolog:
My SWI-Prolog programs/models
Here are some of my SWI-Prolog programs/constraint models. Note: Many of these programs are CLP(FD) programs ported from Picat (see My Picat page), and perhaps there are some traces of Picat here and there.
These programs are also available at my GitHub repo.
Modules
Here are some modules used by the other models.
Module hakank_util.pl
Please note that many programs/models use hakank_utils.pl, so this module should be downloaded as well. It should be loaded as :- use_module(hakank_utils).
.
Here's the content of that module. It is mostly (global) constraints that I miss or wrapper/convenience predicates, especially for clp(fd).
- time2/2
- new_matrix/3
- new_matrix/4
- domain_matrix/2
- print_matrix/1
- matrix_dimensions/3
- latin_square/1
- list_domains/2
- matrix_element/4
- matrix_element2/4
- matrix_element5/4
- matrix_nth1/4 (a better name for matrix_element5/3)
- element2/3
- alldifferent_except_0/1
- alldifferent_except_n/2
- increasing/1
- increasing_strict/1
- decreasing/1
- decreasing_strict/1
- count_occurrences/3
- extract_from_indices/3 (should perhaps be called matrix_elements/3 instead?)
- extract_from_indices2d/3 (should perhaps be called matrix_elements2d/3 instead?)
- scalar_product2/3
- min_list_clp/2
- max_list_clp/2
- slice/4
- to_num/2
- to_num/3
- zip2/3
- zip3/4
- inverse/1
- inverse/2
- between/4
- between_down/3
- numlist_step/3
- same/1
- lex_lt/2
- numlist_cross2/3
- numlist_cross3/4
- diagonal1_slice/2
- diagonal2_slice/2
- prod/2
- regular2/7,
- rotate/2,
- variable_selection/1,
- value_selection/1,
- strategy_selection/1,
- labelings/3,
- atleast/3,
- atmost/3,
- list_domain_disjunction/2,
- make_disj_domain/2,
- create_task/5,
- my_cumulative/4,
- distribute/3,
- sliding_sum/4,
- sliding_sum/3,
- circuit_path/2,
- nvalue/2,
- nvalues/3,
- exactly/3
- alldifferent_modulo/2
- all_differ_from_at_least_k_pos/2
- alldifferent_cst/2
- all_equal/1
- all_min_dist/2
- alldiffer_on_intersection/2
- among/3
- among_seq/5
- among_range/4
- print_attrs_list/1
Module bplan.pl
The bplan module is a simple planner module. It's inspired by some planning modules from the great Prolog introduction book "Thinking as computation" by Hector J. Levesque.
The following predicates are exported
It's used by the following programs:
Models/programs
As mentioned above, almost all the models/program use the module hakank_utils.pl.
- 1d_rubiks_cube.pl: 1D Rubik's Cube planning problem. Note: this program use the bplan module which must be downloaded as well.
- 3_jugs.pl: 3-jugs problem as a shortest path problem (Taha)
- 3_jugs_regular.pl: 3-jugs problem using
regular
constraint
- a_puzzle.pl: "A Puzzle" (from the "God plays dice" blog)
- a_round_of_golf.pl: A Round of Golf puzzle (Dell Logic Problems)
- abbots_puzzle.pl: Abbot's puzzle (Dudeney)
- added_corner.pl: Added Corners puzzle
- ackermann.pl: Ackermann function
- alldiffer_on_intersection.pl: Global constraint
alldiffer_on_intersection
- allpartitions.pl: All partitions of a number
- all_equal.pl: Global constraint
all_equal
- all_interval.pl: All interval problem
- all_differ_from_at_least_k_pos.pl: Global constraint
all_differ_from_at_leats_k_pos
- all_min_dist.pl: Global constraint
all_min_dist
- alldifferent_cst.pl: Decomposition of the global constraint
alldifferent_cst
- alldifferent_except_0.pl: Decomposition of the global constraint
alldifferent_except_0
- alldifferent_modulo.pl: Decomposition of the global constraint
alldifferent_modulo
- alphametic.pl: Fairly general Alphametic solver
- alphametic3.pl: Fairly general Alphametic solver (adds * and -, port of an ECLiPSe model)
- among.pl: Decomposition of the global constraint
among
- among_seq.pl: Decomposition of the global constraint
among_seq
- arch_friends.pl: Arch Friends puzzle (Dell Logic Puzzles)
- assigment.pl: Some assignment problems.
- averbach_1_2.pl: Seating problem (Averbach and Chein)
- averbach_1_3.pl: Logic puzzle (Averbach and Chein)
- babysitting.pl: Babysitting problem (Dell Logic Puzzles)
- bales_of_hay.pl: Bales of Hay proglem (From "The Math Less Traveled")
- bin_packing.pl: Bin packing problems
- bin_packing2.pl: Global constraint
bin_packing
- breaking_news.pl: Breaking News puzzle (Dell Logic Puzzles)
- broken_weights.pl: Broken weights problem (optimized/non-optimized/recursive)
- building_a_house.pl: Building a house (OPL)
- bus_schedule.pl: Bus schedule (Taha: scheduling of buses during a day)
- calculs_d_enfer.pl: Calculs d'enfer puzzle
- changes.pl: Coin changes (minimizing number of coins)
- circling_squares.pl: Circling squares problem (Dudeney)
- circuit.pl: Decomposition of global constraint
circuit
(with some benchmarks/comparison with the built-in version)
- clique.pl: Decomposition of global constraint
clique
- clock_triplets.pl: Clock triplets (Martin Gardner)
- coins_grid.pl: Coins grid problem
- coins3.pl: Two related coins problems.
- combinatorial_auction.pl: Combinatorial Auction
- contracting_costs.pl: Contracting costs
- costas_array.pl: Costas array
- countdown.pl: Simple implementation of Countdown
- covering_opl.pl: Set covering problem (OPL: select workers to build a house)
- crossbar.pl: Crossbar problem (Prolog benchmark)
- crossword2.pl: (Small) crossword problem
- crypta.pl: Cryptarithmetic puzzle (Prolog benchmark problem)
- crypto.pl: Another cryptarithmetic puzzle (Prolog benchmark problem)
- cur_num.pl: Curious Numbers (Dudeney)
- curious_set_of_integers.pl: Curious set of integers (Martin Gardner)
- de_bruijn.pl: de Bruijn sequences (both "classic" and "arbitrary")
- devils_word.pl: Devil's word (sum ASCII value to a certain number, e.g. 666)
- diet.pl: Diet problem
- dinner.pl: A dinner problem
- discrete_tomography.pl: Discrete Tomography
- distribute.pl: Global constraint
distribute/3
- divisible_by_9_through_1.pl: Divisible by 9 through 1 puzzle
- donald_gerald.pl: DONALD + GERALD = ROBERT (Classic alphametic problem)
- dudeney_numbers.pl: Dudebey Numbers (Dudeney)
- eq10.pl: Eq10 problem (Standard Prolog benchmark)
- eq20.pl: Eq20 problem (Standard Prolog benchmark)
- Project Euler problems:
- euler_utils.pl: Utils for Euler problems which include the following:
- proc/1
- run_problems/1
- fib/2
- fib2/2
- even/1
- odd/1
- primes/2
- delete_all/3
- is_prime/1
- is_prime_clp/1
- is_prime2/1
- prime_cp/1
- is_prime_divisors/1
- prime_tabled/1
- prime_tabled_clp/1
- next_prime/2
- next_prime_clp/2
- nth_prime/2
- nth_prime_clp/2
- prime_decomp/2
- divisor/2
- divisors/2
- all_divisors/2
- proper_divisors/2
- num_divisors/2
- sum_proper_divisors/2
- sum_proper_divisors2/2
- sum_all_divisors/2
- prime_divisors/2
- prime_factors/2
- n_factorial/2
- factorial2/2
- factorial3/2
- factorial4/2
- palindromic/1
- palindromic2/1
- lcm/3
- prodlist/2
- mult/3
- num_to_digit_list/2
- digit_list_to_num/2
- digit_list_to_num/3
- to_alpha/2
- list_slices/3
- running_prod/3
- maplist_rev_args/3
- concat_string_list/2
- digits_sum/2
- permutation_cp/3
- euler1.pl: Project Euler problem #1
- euler2.pl: Project Euler problem #2
- euler3.pl: Project Euler problem #3
- euler4.pl: Project Euler problem #4
- euler5.pl: Project Euler problem #5
- euler6.pl: Project Euler problem #6
- euler7.pl: Project Euler problem #7
- euler8.pl: Project Euler problem #8
- euler9.pl: Project Euler problem #9
- euler10.pl: Project Euler problem #10
- euler11.pl: Project Euler problem #11
- euler12.pl: Project Euler problem #12
- euler13.pl: Project Euler problem #13
- euler14.pl: Project Euler problem #14
- euler15.pl: Project Euler problem #15
- euler16.pl: Project Euler problem #16
- euler17.pl: Project Euler problem #17
- euler18.pl: Project Euler problem #18
- euler19.pl: Project Euler problem #19
- euler20.pl: Project Euler problem #20
- euler21.pl: Project Euler problem #21
- euler22.pl: Project Euler problem #22
- euler23.pl: Project Euler problem #23
- euler24.pl: Project Euler problem #24
- euler25.pl: Project Euler problem #25
- euler26.pl: Project Euler problem #26
- euler27.pl: Project Euler problem #27
- euler28.pl: Project Euler problem #28
- euler29.pl: Project Euler problem #29
- euler30.pl: Project Euler problem #30
- euler31.pl: Project Euler problem #31
- euler32.pl: Project Euler problem #32
- euler33.pl: Project Euler problem #33
- euler34.pl: Project Euler problem #34
- euler35.pl: Project Euler problem #35
- euler36.pl: Project Euler problem #36
- euler37.pl: Project Euler problem #37
- euler38.pl: Project Euler problem #38
- euler39.pl: Project Euler problem #39
- euler40.pl: Project Euler problem #40
- euler41.pl: Project Euler problem #41
- euler42.pl: Project Euler problem #42
- euler43.pl: Project Euler problem #43
- euler44.pl: Project Euler problem #44
- euler45.pl: Project Euler problem #45
- euler46.pl: Project Euler problem #46
- euler47.pl: Project Euler problem #47
- euler48.pl: Project Euler problem #48
- euler49.pl: Project Euler problem #49
- euler50.pl: Project Euler problem #50
- exodus.pl: Exodus puzzle (Dell Logic Puzzle)
- exactly.pl: Global constraint
exactly/3
(or rather: testing the constraint)
- extract_from_indices.pl: Test of the constraints
extract_from_indices/3>
and extract_from_indices2d/3>
- fancy.pl: Mr Greenguest puzzle (Fancy dress puzzle)
- farmer.pl: Farmer (goat, wolf, cabbage) planning problem. (uses the bplan module)
- farmer2.pl: Farmer (goat, wolf, cabbage) planning problem, from B-Prolog)
- fib.pl: Fibonacci (from B-Prolog)
- fill_a_pix.pl: Fill-a-Pix grid puzzle
- fill_in_the_squares.pl: Fill in the Squares (Brainjammer)
- finding_celebrities.pl: Finding Celebrities
- five_brigands.pl: Five Brigands (Dudeney)
- four_islands.pl: Four Islands puzzle (Dell Logic puzzles)
- fractions.pl: Fractions problem (Prolog benchmark)
- friends_at_different_floors.pl: Friends at different floors (logic puzzle)
- frustration_patience.pl: Frustration Patience (simulation)
- furniture_moving.pl: Furniture moving (scheduling problem with
cumulative/2
) (aka assignment
)
- futoshiki.pl: Futoshiki grid puzzle
- general_store.pl: General store
- global_contiguity.pl: Global constraint
global_contiguity
- global_contiguity_regular.pl: Global constraint
global_contiguity
using regular
constraint
- golomb_ruler.pl: Golomb ruler problem
- grocery.pl: Grocery puzzle (a.k.a. 7/11 puzzle)
- hakank_utils.pl: Some utils, mostly CLPFD stuff. See above for details.
- hamming_distance.pl: Hamming distance (differences between two binary lists)
- handshaking.pl: Halmos' Handshaking problem
- hanging_weights.pl: Hanging weights
- heterosquare.pl: Heterosquare problem
- hidato.pl: Hidato grid puzzle
- huey_dewey_louie.pl: Huey, Dewey, and Louie problem (Marriott and Stuckey)
- inverse.pl: Global constraints
inverse/1
and inverse/2
- isbn.pl: Some exploration of ISBN13
- jobs_puzzle.pl: Jobs puzzle
- just_forgotten.pl: Just Forgotten puzzle (Enigma #1517)
- kakuro.pl: Kakuro grid puzzle
- K4P2GracefulGraph2.pl: K4P2 Graceful Graph
- kenken2.pl: KenKen grid puzzle
- killer_sudoku.pl: Killer Sudoku
- knapsack.pl: Simple Knapsack problem
- knapsack_rosetta_code_01.pl: 01 Knapsack (Rosetta code)
- knapsack_rosetta_code_bounded.pl: Knapsack bounded (Rosetta code)
- knapsack_investments.pl: Knapsack (investments) (Lundgren, Ronnqvist, Varbrand)
- knapsack_rosetta_code_unbounded.pl: Knapsack unbounded (Rosetta code)
- knight_tour_circuit.pl: Knight tour using
circuit/1
(for matrices NxN where N is even)
- knights_and_knaves_lp.pl: Some Smullyan style Knight and Knaves problems (Adrian Groza)
- labeled_dice.pl: Two dice puzzles: "Labeled dice" and "Building blocks"
- langford.pl: Langford's number problem (
L(2,N)
)
- lady_and_tiger_lp.pl: Some Smullyan style Lady and Tiger problems (Adrian Groza)
- latin_squares_diagonals.pl: Latin squares with diagonals
- lecture_series.pl: Lecture Series (Dell Logic Puzzle)
- least_diff.pl: Least diff problem (minimize there difference between ABCDE - FGHIJ)
- lectures.pl: Lecture scheduling (simple) (Biggs)
- light_meal.pl: Light meal problem (Colmerauer, Prolog III)
- magic_hexagon.pl: Magic hexagon (CSPLib #023)
- magic_sequence.pl: Magic sequence (CLP and non-CLP approaches)
- magic_square.pl: Magic square
- magic_square_and_cards.pl: Magic square and cards (Martin Gardner)
- mamas_age.pl: Mama's age (Dudeney)
- map_coloring.pl: Map coloring (simple)
- mankell.pl: Generating all spellings of Henning Mankell (and Kjellerstrand)
- marathon2.pl: Marathon puzzle
- max_flow_winston1.pl: Max flow problem (Winston OR book)
- minesweeper.pl: Minesweeper puzzle
- monks_and_doors.pl: Monks and Door problem (Roland Bol)
- mortgage.pl: Mortgage experiments (using
clpr
)
- mr_smith.pl: Mr Smith party problem (IF Prolog)
- music_men.pl: Music men problem (logical puzzle)
- nadel.pl: Nadel's construction problem (Rina Dechter)
- number_lock2.pl: Number lock problem (2 variants), as well as generating new puzzles.
- nvalue.pl: Global constraint
nvalue/2
(or rather: testing the constraint)
- nvalues.pl: Global constraint
nvalues/3
(or rather: testing the constraint)
- number_of_days.pl: Number of Days (knapsack) (Nathan Brixius)
- olympic.pl: Olympic puzzle (standard Prolog problem)
- organize_day.pl: Organize a day (simple scheduling)
- p_median.pl: P-Median problem (OPL)
- pair_divides_the_sum.pl: Pair divides the sum
- pandigital_numbers.pl: Pandigital numbers
- perfect_square_sequence.pl: Perfect square sequence (from "Fun with num3ers")
- pert.pl: Simple PERT model (P. Van Hentenryck)
- photo_problem.pl: Photo problem
- pigeon_hole.pl: Pigeon hole problem
- place_number_puzzle.pl: Place number puzzle
- pythagoras.pl: Pythagoras problem
- quasigroup_completion.pl: Quasigroup completion problem
- queens.pl: N-queens problem.
- rabbits.pl: Rabbits problem (Van Hentenryck)
- regular.pl: Decomposition of global constraint
regular
(and testing some DFA's)
- remainders.pl: Remainders problem (Kordemsky)
- remarkable_sequence.pl: Remarkable sequence
- safe_cracking.pl: Safe cracking puzzle
- schedule1.pl: (Simple Scheduling problem (SICStus Prolog)
- schedule2.pl: (Simple Scheduling problem (use
my_cumulative/4
)
- scheduling_speakers.pl: Scheduling speakers (R. Dechter)
- schoolgirls.pl: Schoolgirl logic puzzle
- scrabble_contest.pl: Scrabble and Chess Contest puzzle
- secret_santa.pl: Secret Santa problem
- secret_santa2.pl: Secret Santa problem II (Maple Primes)
- send_more_money.pl: SEND+MORE=MONEY (several implementations, both CLP and non-CLP)
- send_more_money_any_base.pl: SEND+MORE=MONEY in any base
- send_most_money.pl: SEND+MOST=MONEY, and maximize the value of MONEY
- sequence_problem.pl: Sequence problem (Marriott and Stuckey)
- seseman.pl: Seseman convent problem.
- set_covering.pl: Set covering problem (Winston: Placing fire stations)
- set_covering2.pl: Set covering problem (Taha: Placing security telephones)
- set_covering3.pl: Set covering problem (Murty: Selecting senators for committees)
- set_covering4.pl: Set covering/set partition problem (Lundgren, Ronnqvist, Varbrand)
- set_covering_deployment.pl: Set covering deployment (optimal stationing of troops)
- set_covering_skiena.pl: Set covering (example from S. Skiena)
- shifted_division.pl: Shifted division
- sicherman_dice.pl: Sicherman dice
- ski_assignment.pl: Ski assignment puzzle
- sliding_sum.pl: Global constraint
sliding_sum
- smugglers_knapsack.pl: Smuggler's Knapsack (Marriott and Stuckey)
- smullyan_lion_and_unicorn.pl: Some Lion and Unicorn puzzles (Smullyan)
- sonet.pl: SONET network design problem
- spreadsheet.pl: Simple spreadsheet (using
clpr
)
- square_root_of_wonderful.pl: Square root of Wonderful (Martin Gardner)
- stable_marriage.pl: Stable Marriage problem
- steiner.pl: Steiner triplets
- strimko2.pl: Strimko grid puzzle
- stuckey_seesaw.pl: Balancing on a seesaw (Marriott and Stuckey)
- subset_sum.pl: Subset sum problem (Murty: Stolen coin bags)
- subset_sum2.pl: Subset sum problem with large integers
- sudoku.pl: Sudoku
- survo_puzzle.pl: Survo puzzle
- talisman_square.pl: Talisman Squar
- telephone_number.pl: Telephone number sequence
e
- the_family_puzzle.pl: The Family Puzzle (logic puzzle)
- timpkin.pl: Mrs Timpkin's Age (Dudeney)
- to_num.pl:
to_num(List,Base,Number)
: Convert a number to/from a list of digits (e.g. for alphametic problems)
- torn_numbers.pl: tourist_site_competition.pl: Tourist Site Competition (P. Flener)
- traffic_lights.pl: Traffic lights problem
- tsp.pl: Traveling salesperson problem
- tunapalooza.pl: Tunapalooza puzzle (Dell Logic Puzzle)
- twin_letters.pl: Twin Letters puzzle
- volsay1.pl: Volsay problem (OPL)
- volsay2.pl: Volsay problem, variant (OPL)
- volsay3.pl: Volsay problem, another variant (OPL)
- war_or_peace.pl: War or Peace problem
- warehouse.pl: Warehouse location problem (OPL)
- water.pl: Water jugs problem (uses the bplan module)
- who_killed_agatha.pl: Who killed Agatha problem (The Dreadsbury Mansion Murder Mystery)
- who_killed_the_bosmer.pl: Who killed the Bosmer? (logic puzzle)
- wordle.pl: Wordle solver
- wordle_dcg.pl: Wordle solver using DCGs
- xkcd.pl: xkcd #287 puzzle (the one with the knapsack/subset sum menu problem)
- young_tableaux.pl: Young tableaux and partition
- zebra.pl: Zebra puzzle
Also, see my other pages about constraint programming systems:
* My Constraint Programming Blog
* Constraint Programming
* Common constraint programming problems
* My MiniZinc page
* My JaCoP page
* My JaCoP/Scala page
* My Choco page
* My Gecode/R page
* My Comet page
* My Gecode page
* My ECLiPSe page
* My Tailor/Essence' page
* My SICStus Prolog page
* My Google CP Solver page
* My OscaR page
* My JSR-331 page
* My Numberjack page
* My AIMMS+CP page
* My B-Prolog page
* My Choco3 page
* My Picat page
* My Z3 page
Back to my homepage
Created by Hakan Kjellerstrand hakank@gmail.com