potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
599 stars 79 forks source link

errors #427

Closed swealjack closed 1 year ago

daveraja commented 1 year ago

Yes there is something wrong with your syntax.

ASP doesn't support the list syntax of Prolog.

While you can use recursive head-tail tuple pairs to simulate this style of list syntax it is usually a bad idea. It can lead to a grounding blowup and is typically not a good way to think about modelling a problem in ASP.

Have a look at the Potassco Guide for the ASP syntax:

https://github.com/potassco/guide/releases/download/v2.2.0/guide.pdf

and for more general tutorials and documentation:

https://potassco.org/doc/

Cheers.

Dave

On 5/16/23 13:52, swealjack wrote:

hello, i am wriitng an asp program for semester planning. following is my code

`% Define the courses course("MATH501"). course("COMP502"). course("PHYS503"). course("ENG504"). course("BUS505").

% Define the prerequisites prerequisite("COMP502", ["MATH501"]). prerequisite("PHYS503", ["MATH501"]). prerequisite("BUS505", ["ENG504"]).

% Define the semester semester(1). semester(2). semester(3). semester(4).

% Define the maximum number of credits per semester max_credits_per_semester(15).

% Define the total number of credits required to graduate required_credits(120).

% Define the facts to indicate if a course has been completed completed(["MATH501"]). % Assume no other courses have been completed

% Define the rules to output the semester plan % Output all courses that can be taken in a given semester output_semester(Semester) :- semester(Semester), format("Semester ~d:~n", [Semester]), findall(Course, (course(Course), can_take_course(Course, Semester)), Courses), output_courses(Courses), format("~n", []).

% Output all courses in a list output_courses([]). output_courses([Course|Courses]) :- format("- wn", [Course]), output_courses(Courses).

% Define the rules to determine if a course can be taken in a given semester can_take_course(Course, Semester) :- % Check if the course has been completed already not(member(Course, CompletedCourses)), % Check if the course has all prerequisites completed prerequisite(Course, Prereqs), forall(member(Prereq, Prereqs), member(Prereq, CompletedCourses)), % Check if the course can fit in the current semester credits(Course, Credits), total_credits(Semester, TotalCredits), Credits =< max_credits_per_semester - TotalCredits.

% Define the rules to calculate the total credits taken in a semester total_credits(Semester, TotalCredits) :- findall(Credits, (course(Course), member(Course, CompletedCourses), semester_taken(Course, Semester), credits(Course, Credits)), CreditsList), sum_list(CreditsList, TotalCredits).

% Define the rules to indicate which semester a course was taken semester_taken("MATH501", 1). semester_taken("COMP502", 2). semester_taken("PHYS503", 2). semester_taken("ENG504", 3). semester_taken("BUS505", 4).`

when i run the program i face following errors. is there somehting wrong with my syntax?

clingo version 5.6.2 Reading from clingo.lp clingo.lp:9:25-26: error: syntax error, unexpected [

clingo.lp:10:25-26: error: syntax error, unexpected [

clingo.lp:11:24-25: error: syntax error, unexpected [

clingo.lp:26:11-12: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:33:30-31: error: syntax error, unexpected [

clingo.lp:39:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:40:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:47:42-43: error: syntax error, unexpected ","

*** ERROR: (clingo): parsing failed

— Reply to this email directly, view it on GitHub https://github.com/potassco/clingo/issues/427, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHCLVT7RX6BH7OZ26BKSRTXGL2ZPANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

swealjack commented 1 year ago

So what changes should I make in my code ? Unfortunately there is no IDE that can suggest me how to correct the syntax errors

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: David Rajaratnam @.> Sent: Tuesday, May 16, 2023 6:31:48 AM To: potassco/clingo @.> Cc: swealjack @.>; Author @.> Subject: Re: [potassco/clingo] clingo syntax errors (Issue #427)

Yes there is something wrong with your syntax.

ASP doesn't support the list syntax of Prolog.

While you can use recursive head-tail tuple pairs to simulate this style of list syntax it is usually a bad idea. It can lead to a grounding blowup and is typically not a good way to think about modelling a problem in ASP.

Have a look at the Potassco Guide for the ASP syntax:

https://github.com/potassco/guide/releases/download/v2.2.0/guide.pdf

and for more general tutorials and documentation:

https://potassco.org/doc/

Cheers.

Dave

On 5/16/23 13:52, swealjack wrote:

hello, i am wriitng an asp program for semester planning. following is my code

`% Define the courses course("MATH501"). course("COMP502"). course("PHYS503"). course("ENG504"). course("BUS505").

% Define the prerequisites prerequisite("COMP502", ["MATH501"]). prerequisite("PHYS503", ["MATH501"]). prerequisite("BUS505", ["ENG504"]).

% Define the semester semester(1). semester(2). semester(3). semester(4).

% Define the maximum number of credits per semester max_credits_per_semester(15).

% Define the total number of credits required to graduate required_credits(120).

% Define the facts to indicate if a course has been completed completed(["MATH501"]). % Assume no other courses have been completed

% Define the rules to output the semester plan % Output all courses that can be taken in a given semester output_semester(Semester) :- semester(Semester), format("Semester ~d:~n", [Semester]), findall(Course, (course(Course), can_take_course(Course, Semester)), Courses), output_courses(Courses), format("~n", []).

% Output all courses in a list output_courses([]). output_courses([Course|Courses]) :- format("- wn", [Course]), output_courses(Courses).

% Define the rules to determine if a course can be taken in a given semester can_take_course(Course, Semester) :- % Check if the course has been completed already not(member(Course, CompletedCourses)), % Check if the course has all prerequisites completed prerequisite(Course, Prereqs), forall(member(Prereq, Prereqs), member(Prereq, CompletedCourses)), % Check if the course can fit in the current semester credits(Course, Credits), total_credits(Semester, TotalCredits), Credits =< max_credits_per_semester - TotalCredits.

% Define the rules to calculate the total credits taken in a semester total_credits(Semester, TotalCredits) :- findall(Credits, (course(Course), member(Course, CompletedCourses), semester_taken(Course, Semester), credits(Course, Credits)), CreditsList), sum_list(CreditsList, TotalCredits).

% Define the rules to indicate which semester a course was taken semester_taken("MATH501", 1). semester_taken("COMP502", 2). semester_taken("PHYS503", 2). semester_taken("ENG504", 3). semester_taken("BUS505", 4).`

when i run the program i face following errors. is there somehting wrong with my syntax?

clingo version 5.6.2 Reading from clingo.lp clingo.lp:9:25-26: error: syntax error, unexpected [

clingo.lp:10:25-26: error: syntax error, unexpected [

clingo.lp:11:24-25: error: syntax error, unexpected [

clingo.lp:26:11-12: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:33:30-31: error: syntax error, unexpected [

clingo.lp:39:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:40:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:47:42-43: error: syntax error, unexpected ","

*** ERROR: (clingo): parsing failed

— Reply to this email directly, view it on GitHub https://github.com/potassco/clingo/issues/427, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHCLVT7RX6BH7OZ26BKSRTXGL2ZPANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/potassco/clingo/issues/427#issuecomment-1548975534, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEY6XVLBEHPZZRI5TTLHVOLXGL7LJANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you authored the thread.Message ID: @.***>

daveraja commented 1 year ago

As mentioned earlier, using a list representation is not how you typically encode a problem in ASP.  So fixing your code is not a simple matter of correcting the syntax errors. Instead, it requires thinking about what is a good way to model the problem and how to capture the relationship between the different concepts.

For example, in your example why do you use a list to represent the prerequisites of a course? A list has a fixed ordering so is the ordering in the list important? If you simply want to represent that a course A is a prerequisite of another course B then you can just encode this fact as something like "prerequisite(A,B)". There is no list necessary.

The Potassco Guide and the other links on the Potassco documents page provide links to various tutorials and documentation which is a good place to start to get an understanding of how to model problems using ASP.

On 5/16/23 16:21, swealjack wrote:

So what changes should I make in my code ? Unfortunately there is no IDE that can suggest me how to correct the syntax errors

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: David Rajaratnam @.> Sent: Tuesday, May 16, 2023 6:31:48 AM To: potassco/clingo @.> Cc: swealjack @.>; Author @.> Subject: Re: [potassco/clingo] clingo syntax errors (Issue #427)

Yes there is something wrong with your syntax.

ASP doesn't support the list syntax of Prolog.

While you can use recursive head-tail tuple pairs to simulate this style of list syntax it is usually a bad idea. It can lead to a grounding blowup and is typically not a good way to think about modelling a problem in ASP.

Have a look at the Potassco Guide for the ASP syntax:

https://github.com/potassco/guide/releases/download/v2.2.0/guide.pdf

and for more general tutorials and documentation:

https://potassco.org/doc/

Cheers.

Dave

On 5/16/23 13:52, swealjack wrote:

hello, i am wriitng an asp program for semester planning. following is my code

`% Define the courses course("MATH501"). course("COMP502"). course("PHYS503"). course("ENG504"). course("BUS505").

% Define the prerequisites prerequisite("COMP502", ["MATH501"]). prerequisite("PHYS503", ["MATH501"]). prerequisite("BUS505", ["ENG504"]).

% Define the semester semester(1). semester(2). semester(3). semester(4).

% Define the maximum number of credits per semester max_credits_per_semester(15).

% Define the total number of credits required to graduate required_credits(120).

% Define the facts to indicate if a course has been completed completed(["MATH501"]). % Assume no other courses have been completed

% Define the rules to output the semester plan % Output all courses that can be taken in a given semester output_semester(Semester) :- semester(Semester), format("Semester ~d:~n", [Semester]), findall(Course, (course(Course), can_take_course(Course, Semester)), Courses), output_courses(Courses), format("~n", []).

% Output all courses in a list output_courses([]). output_courses([Course|Courses]) :- format("- wn", [Course]), output_courses(Courses).

% Define the rules to determine if a course can be taken in a given semester can_take_course(Course, Semester) :- % Check if the course has been completed already not(member(Course, CompletedCourses)), % Check if the course has all prerequisites completed prerequisite(Course, Prereqs), forall(member(Prereq, Prereqs), member(Prereq, CompletedCourses)), % Check if the course can fit in the current semester credits(Course, Credits), total_credits(Semester, TotalCredits), Credits =< max_credits_per_semester - TotalCredits.

% Define the rules to calculate the total credits taken in a semester total_credits(Semester, TotalCredits) :- findall(Credits, (course(Course), member(Course, CompletedCourses), semester_taken(Course, Semester), credits(Course, Credits)), CreditsList), sum_list(CreditsList, TotalCredits).

% Define the rules to indicate which semester a course was taken semester_taken("MATH501", 1). semester_taken("COMP502", 2). semester_taken("PHYS503", 2). semester_taken("ENG504", 3). semester_taken("BUS505", 4).`

when i run the program i face following errors. is there somehting wrong with my syntax?

clingo version 5.6.2 Reading from clingo.lp clingo.lp:9:25-26: error: syntax error, unexpected [

clingo.lp:10:25-26: error: syntax error, unexpected [

clingo.lp:11:24-25: error: syntax error, unexpected [

clingo.lp:26:11-12: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:33:30-31: error: syntax error, unexpected [

clingo.lp:39:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:40:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:47:42-43: error: syntax error, unexpected ","

*** ERROR: (clingo): parsing failed

— Reply to this email directly, view it on GitHub https://github.com/potassco/clingo/issues/427, or unsubscribe

https://github.com/notifications/unsubscribe-auth/AAHCLVT7RX6BH7OZ26BKSRTXGL2ZPANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/potassco/clingo/issues/427#issuecomment-1548975534, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEY6XVLBEHPZZRI5TTLHVOLXGL7LJANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/potassco/clingo/issues/427#issuecomment-1549058634, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHCLVXJYEMMFGLAXMVY2VLXGMMHZANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you commented.Message ID: @.***>

rkaminsk commented 1 year ago

What you are using here is/was clearly a Prolog program. Even though ASP and Prolog share some syntax similarities they are completely different languages. I would recommend to develop the ASP encoding step by step.

jschneeberger commented 1 year ago

hi there,

in addition the hints from Dave and Roland I try to give you an impression of a ASP (not Prolog) encoding. I removed a lot of details but this is only for a start.

% Define the courses course("MATH501"; "COMP502"; "PHYS503"; "ENG504"; "BUS505").

% Define the prerequisites prerequisite("COMP502", "MATH501"). prerequisite("PHYS503", "MATH501"). prerequisite("BUS505", "ENG504").

% Define the facts to indicate if a course has been completed % Assume no other courses have been completed completed("MATH501").

% Calculate models which courses can be taken { can_take_course(Course) } :- course(Course), not completed(Course).

% Constraint: Eliminate models where prerequisites are not accomplished :- can_take_course(Course), prerequisite(Course, Prereqs), not completed(Prereqs).

show can_take_course/1.

Clingo will return the following models

Answer: 1

Answer: 2 can_take_course("PHYS503") Answer: 3 can_take_course("ENG504") Answer: 4 can_take_course("PHYS503") can_take_course("ENG504") Answer: 5 can_take_course("COMP502") Answer: 6 can_take_course("COMP502") can_take_course("ENG504") Answer: 7 can_take_course("COMP502") can_take_course("PHYS503") Answer: 8 can_take_course("COMP502") can_take_course("PHYS503") can_take_course("ENG504") SATISFIABLE

Models       : 8

Hope this helps. Josef

Am 16.05.2023 um 05:52 schrieb swealjack:

hello, i am wriitng an asp program for semester planning. following is my code

`% Define the courses course("MATH501"). course("COMP502"). course("PHYS503"). course("ENG504"). course("BUS505").

% Define the prerequisites prerequisite("COMP502", ["MATH501"]). prerequisite("PHYS503", ["MATH501"]). prerequisite("BUS505", ["ENG504"]).

% Define the semester semester(1). semester(2). semester(3). semester(4).

% Define the maximum number of credits per semester max_credits_per_semester(15).

% Define the total number of credits required to graduate required_credits(120).

% Define the facts to indicate if a course has been completed completed(["MATH501"]). % Assume no other courses have been completed

% Define the rules to output the semester plan % Output all courses that can be taken in a given semester output_semester(Semester) :- semester(Semester), format("Semester ~d:~n", [Semester]), findall(Course, (course(Course), can_take_course(Course, Semester)), Courses), output_courses(Courses), format("~n", []).

% Output all courses in a list output_courses([]). output_courses([Course|Courses]) :- format("- wn", [Course]), output_courses(Courses).

% Define the rules to determine if a course can be taken in a given semester can_take_course(Course, Semester) :- % Check if the course has been completed already not(member(Course, CompletedCourses)), % Check if the course has all prerequisites completed prerequisite(Course, Prereqs), forall(member(Prereq, Prereqs), member(Prereq, CompletedCourses)), % Check if the course can fit in the current semester credits(Course, Credits), total_credits(Semester, TotalCredits), Credits =< max_credits_per_semester - TotalCredits.

% Define the rules to calculate the total credits taken in a semester total_credits(Semester, TotalCredits) :- findall(Credits, (course(Course), member(Course, CompletedCourses), semester_taken(Course, Semester), credits(Course, Credits)), CreditsList), sum_list(CreditsList, TotalCredits).

% Define the rules to indicate which semester a course was taken semester_taken("MATH501", 1). semester_taken("COMP502", 2). semester_taken("PHYS503", 2). semester_taken("ENG504", 3). semester_taken("BUS505", 4).`

when i run the program i face following errors. is there somehting wrong with my syntax?

clingo version 5.6.2 Reading from clingo.lp clingo.lp:9:25-26: error: syntax error, unexpected [

clingo.lp:10:25-26: error: syntax error, unexpected [

clingo.lp:11:24-25: error: syntax error, unexpected [

clingo.lp:26:11-12: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:33:30-31: error: syntax error, unexpected [

clingo.lp:39:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:40:16-17: error: syntax error, unexpected [, expecting ) or ;

clingo.lp:47:42-43: error: syntax error, unexpected ","

*** ERROR: (clingo): parsing failed

— Reply to this email directly, view it on GitHub https://github.com/potassco/clingo/issues/427, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFNKMLATP647LV6F5HPVNLXGL2ZPANCNFSM6AAAAAAYDBGZAQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Dr. Josef Schneeberger @.*** Trödelmarkt 42, D-90403 Nürnberg +49 172 8613281

swealjack commented 1 year ago

hi when i run your program i only get one module in my anaconda. so is there an issue with my anaconda? image

rkaminsk commented 1 year ago

Please have a look at an ASP tutorial or some introductory material. Your questions are too basic to answer them one by one.

For example, our group offers plenty some material:

I also really recommend the book by Vladimir Lifschitz: