Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
InteGraal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Boreal
InteGraal
Commits
aa36c3d4
Commit
aa36c3d4
authored
2 months ago
by
Federico Ulliana
Browse files
Options
Downloads
Patches
Plain Diff
added nice print method for horn clauses
parent
19ba61a8
No related branches found
No related tags found
1 merge request
!68
Resolve "add explanation module"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
integraal/integraal-explanation/src/main/java/fr/boreal/explanation/tracker_gri/encoders/AbstractGSATEncoder_TrackerGRI.java
+37
-2
37 additions, 2 deletions
.../tracker_gri/encoders/AbstractGSATEncoder_TrackerGRI.java
with
37 additions
and
2 deletions
integraal/integraal-explanation/src/main/java/fr/boreal/explanation/tracker_gri/encoders/AbstractGSATEncoder_TrackerGRI.java
+
37
−
2
View file @
aa36c3d4
...
@@ -10,7 +10,8 @@ import fr.boreal.model.logicalElements.api.*;
...
@@ -10,7 +10,8 @@ import fr.boreal.model.logicalElements.api.*;
import
fr.boreal.model.rule.api.FORule
;
import
fr.boreal.model.rule.api.FORule
;
import
fr.boreal.model.rule.api.Rule
;
import
fr.boreal.model.rule.api.Rule
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
/**
* This abstract class contains the main algorithm for encoding factbase with 4 additional abstract methods
* This abstract class contains the main algorithm for encoding factbase with 4 additional abstract methods
...
@@ -145,6 +146,8 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
...
@@ -145,6 +146,8 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
private
void
encode
(
Atom
headAtom
,
Set
<
Atom
>
tempAnc
,
Rule
rule
,
LineageTracker
gri
)
{
private
void
encode
(
Atom
headAtom
,
Set
<
Atom
>
tempAnc
,
Rule
rule
,
LineageTracker
gri
)
{
System
.
out
.
println
(
"\nencoding head: "
+
headAtom
+
" body: "
+
tempAnc
+
" rule: "
+
rule
);
int
currentRuleIDAsGroupNumber
;
int
currentRuleIDAsGroupNumber
;
if
(
ruleIDMap
.
inverse
().
containsKey
(
rule
))
{
if
(
ruleIDMap
.
inverse
().
containsKey
(
rule
))
{
...
@@ -157,6 +160,7 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
...
@@ -157,6 +160,7 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
List
<
Integer
>
ruleInstaceGroupClause
=
new
ArrayList
<>();
List
<
Integer
>
ruleInstaceGroupClause
=
new
ArrayList
<>();
ruleInstaceGroupClause
.
addFirst
(
currentRuleIDAsGroupNumber
);
ruleInstaceGroupClause
.
addFirst
(
currentRuleIDAsGroupNumber
);
List
<
List
<
Integer
>>
tmpclauses
=
new
ArrayList
<>();
// process the body atom
// process the body atom
for
(
Atom
relevantAtom
:
tempAnc
)
{
for
(
Atom
relevantAtom
:
tempAnc
)
{
...
@@ -177,7 +181,7 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
...
@@ -177,7 +181,7 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
factIDMap
.
put
(
relAtomGroupID
,
relevantAtom
);
factIDMap
.
put
(
relAtomGroupID
,
relevantAtom
);
}
}
// Create a singleton group with the atom to the gcnf
// Create a singleton group with the atom to the gcnf
clauses
.
add
(
List
.
of
(
relAtomGroupID
,
propVarIDForCurrentAtom
));
tmp
clauses
.
add
(
List
.
of
(
relAtomGroupID
,
propVarIDForCurrentAtom
));
}
}
// Add each relevant atom to the (body of) horn clause
// Add each relevant atom to the (body of) horn clause
...
@@ -192,7 +196,38 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
...
@@ -192,7 +196,38 @@ public abstract class AbstractGSATEncoder_TrackerGRI implements GSATEncoder_GRI<
// The clause is ready
// The clause is ready
clauses
.
add
(
ruleInstaceGroupClause
);
clauses
.
add
(
ruleInstaceGroupClause
);
clauses
.
addAll
(
tmpclauses
);
clauses
.
forEach
(
this
::
printHornClause
);
}
public
void
printHornClause
(
List
<
Integer
>
clause
)
{
if
(
clause
==
null
||
clause
.
isEmpty
())
{
System
.
out
.
println
(
"Invalid clause"
);
return
;
}
// Extract group number (first element)
int
group
=
clause
.
get
(
0
);
// Extract head and body
int
head
=
0
;
List
<
Integer
>
body
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<
clause
.
size
();
i
++)
{
int
literal
=
clause
.
get
(
i
);
if
(
literal
>
0
)
{
head
=
literal
;
// Positive literal is the head
}
else
{
body
.
add
(-
literal
);
// Convert negative literals to positive for printing
}
}
// Print the Horn clause in the required format
System
.
out
.
print
(
"{"
+
group
+
"} "
);
if
(!
body
.
isEmpty
())
{
System
.
out
.
print
(
body
.
stream
().
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
"^"
))
+
" -> "
);
}
System
.
out
.
println
(
head
);
}
}
public
abstract
int
computeRuleID
();
public
abstract
int
computeRuleID
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment