-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetlog.pl
8830 lines (7845 loc) · 343 KB
/
setlog.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% The {log} interpreter and solver
%%
%% VERSION 4.9.6
%%
%% original development by
%% Agostino Dovier Eugenio Omodeo
%% Enrico Pontelli Gianfranco Rossi
%%
%% subsequent enhancements by
%% Gianfranco Rossi
%% with the contribution of
%% B.Bazzan S.Manzoli S.Monica C.Piazza L.Gelsomino
%%
%% Last revision by
%% Gianfranco Rossi and Maximiliano Cristia'
%% (November 2019)
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(setlog,[
op(980,xfx,:),
op(970,xfy,or),
op(950,xfy,&),
op(900,fy,[neg,naf]),
op(800,xf,!),
op(700,xfx,[in,neq,nin]),
op(670,xfx,\),
op(650,yfx,[with,mwith]),
op(150,fx,*),
setlog/0, % for interactive use
setlog/1, % to call setlog from Prolog
setlog/2,
setlog/3,
setlog/4,
setlog/5,
setlog_InOut/3,
setlog_InOut_partial/3,
setlog_InOut_SC/3,
setlog_consult/1,
consult_lib/0,
setlog_clause/1,
setlog_config/1,
setlog_rw_rules/0,
setlog_help/0,
h/1
]).
:- use_module(library(dialect/sicstus/timeout)).
:- dynamic isetlog/2.
:- dynamic newpred_counter/1.
:- dynamic context/1.
:- dynamic final/0. %default: no final
:- dynamic nowarning/0. %default: warning
:- dynamic filter_on/0. %default: no filter_on
:- dynamic nolabel/0. %default: label
:- dynamic noneq_elim/0. %default: neq_elim
:- dynamic noran_elim/0. %default: ran_elim
:- dynamic nocomp_elim/0. %default: comp_elim
:- dynamic noirules/0. %default: irules
:- dynamic subset_elim/0. %default: no subset_elim
:- dynamic trace/1. %default: no trace
:- dynamic int_solver/1. %default: as specified by default_int_solver/1
:- dynamic strategy/1. %modifiable configuration params
:- dynamic path/1.
:- dynamic rw_rules/1.
:- dynamic fd_labeling_strategy/1.
:- multifile replace_rule/6.
:- multifile inference_rule/7.
:- multifile fail_rule/6.
:- multifile equiv_rule/3.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% %%%%%%%%%%%%%%
%%%%%%%%%%% {log} interactive environment %%%%%%%%%%%%%%
%%%%%%%%%%% %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The following predicates implement the {log}
% interactive programming environment. This environment
% offers a Prolog-like user interface, enriched with facilities
% for manipulating sets and multi-sets. The most notable
% syntactic differences w.r.t. std Prolog are: the use of '&' in
% place of ',' to represent goal conjunction; the use of 'or'
% in place of ';' to represent goal disjunction; the use of
% 'neg' or 'naf' in place of '\+' to represent negation (resp.,
% simplified Constructive Negation and Negation as Failure).
% To enter the {log} interactive environment call the goal
% 'setlog.'. To exit, call the goal 'halt.'.
% N.B. {log}, in the current version, provides only a small
% subset of Prolog built-ins and no support for program
% debugging at {log} program level.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setlog :-
% welcome_message,
set_default,
top_level.
set_default :-
cond_retract(nowarning), %restore default value: warning
set_default_control,
cond_retract(nolabel), %restore default value: label
retract_trace, %restore default value: no trace
default_int_solver(IS),
ssolve(int_solver(IS),[],[]). %restore default value: clpfd
set_default_control :-
cond_retract(noirules), %restore default value: irules
cond_retract(noneq_elim), %restore default value: neq_elim
cond_retract(noran_elim), %restore default value: ran_elim
cond_retract(nocomp_elim), %restore default value: comp_elim
cond_retract(final), %restore default value: no final
cond_retract(subset_elim). %restore default value: no subset_elim
top_level :-
cond_retract(final), %restore default value: no final
nl, write('{log}=> '), %flush_output(),
setlog_read_term(Goal,[variable_names(VarNames)]), %e.g. VarNames=[X=_1,S=_2,Y=_3,R=_4]
solve(Goal,Constr),
skip_return,
add_intv(Constr,ConstrAll,_),
filter_and_check_w(ConstrAll,RConstrAll,_),
chvar([],_,v(VarNames,RConstrAll),_,_,v(VarNames1,Constr1)), %e.g. VarNames1=[X=_20,S=_21,Y=_22,R=23],[set(_23)]))
postproc(Constr1,Constr1Ext),
mk_subs_ext(VarNames1,VarNames_ext1), %e.g. VarNames1=[X=X,S=R with X,Y=X,R=R] VarNames_ext1=[S={X/R},Y=X,true,true]
extract_vars(VarNames_ext1,Vars), %e.g. VarNames_ext1=[S={Y/_7},R={X/_7},true,true] Vars=[_7]
extract_vars(Constr1,ConstrVars),
rename_fresh_vars(Vars,1,N),
rename_fresh_vars(ConstrVars,N,_),
% nl, write_subs_constr(VarNames_ext1,Constr1,Vars),
nl, write_subs_constr(VarNames_ext1,Constr1Ext,Vars),
top_level.
top_level :-
nl,write(no),nl,
skip_return,
top_level.
welcome_message :-
nl, nl,
write(' WELCOME TO {log} - version 4.9 '),
nl, nl.
%%%%%%%%%%%
setlog_read_term(Goal,Vars) :-
on_exception(Msg,read_term(Goal,Vars),syntax_error_msg(Msg)).
syntax_error_msg(Text) :-
write('Syntax error:'), nl,
write(Text), nl,
fail.
skip_return :-
read_pending_input(user_input,_C,[]).
%%%%%%%%%%%
mk_subs_ext(VarSubs,VarSubsMin) :-
postproc(VarSubs,VarSubsExt),
mk_subs_vv(VarSubsExt,VarSubsMin).
mk_subs_vv([],[]).
mk_subs_vv([N1=V1|Subs],R) :-
var(V1),!,
V1 = N1,
mk_subs_vv(Subs,SubsMin),
append(SubsMin,[true],R).
mk_subs_vv([N1=V1|Subs],[N1=V1|R]) :-
mk_subs_vv(Subs,R).
%%%%%%%%%%% write substitutions and constraints
write_subs_constr([],[],_) :- !,
write(yes), nl.
write_subs_constr(Subs,Constr,Vars) :-
(Subs = [],!, true
;
Subs = [true|_],!,write('true'),Prn=y
;
write_subs_all(Subs,Prn)
),
write_constr(Constr,Vars,Prn),
ask_the_user(Prn).
ask_the_user(Prn):-
var(Prn),!.
ask_the_user(_):-
nl,
nl, write('Another solution? (y/n)'),
get_single_char(C),
(C \== 121,! % 'y'
;
cond_retract(nowarning), fail
).
write_subs_all([],_).
write_subs_all([N1=V1|R],Prn) :-
write(N1), write(' = '), write(V1), Prn=y,
(R = [],!,true ;
R = [true|_],!,true ;
write(', '), nl, write_subs_all(R,Prn) ).
%write_constr(Constr,Vars,Prn) :-
%postproc(Constr,Constr_ext),
write_constr(Constr_ext,Vars,Prn) :-
write_eqconstr_first(Constr_ext,Constr_ext_noeq),
write_constr_first(Constr_ext_noeq,Vars,Prn).
write_eqconstr_first([],[]) :- !.
write_eqconstr_first([T1 = T2|R],NewR) :-
var(T1),!,
write(', '), nl,
write(T1), write(' = '), write(T2),
write_eqconstr_first(R,NewR).
write_eqconstr_first([T1 = T2|R],NewR) :-
var(T2),!,
write(', '), nl,
write(T2), write(' = '), write(T1),
write_eqconstr_first(R,NewR).
write_eqconstr_first([C|R],[C|NewR]) :-
write_eqconstr_first(R,NewR).
write_constr_first([],_,_) :- !.
write_constr_first([C|Constr],Vars,Prn) :-
nl, write('Constraint: '),
write_atomic_constr(C), Prn=y,
write_constr_all(Constr,Vars).
write_constr_all([],_) :- !.
write_constr_all([C|Constr],Vars) :-
write(', '), write_atomic_constr(C),
write_constr_all(Constr,Vars).
write_atomic_constr(solved(C,_,_,_)) :- !,
write(C).
write_atomic_constr(delay(irreducible(C)&true,_)) :- !,
write(irreducible(C)).
write_atomic_constr(C) :- !,
write(C).
%%%%%%%%%%%
rename_fresh_vars([],Num,Num) :- !.
rename_fresh_vars([X|R],Num,NumF) :-
var(X),!,
name(Num,NumCodeList),
% append([78,95],NumCodeList,CodeList), %N_
% append([78],NumCodeList,CodeList),
append([95,78],NumCodeList,CodeList), %_N
name(XNew,CodeList),
X=XNew,
Num1 is Num + 1,
rename_fresh_vars(R,Num1,NumF).
rename_fresh_vars([_X|R],Num,NumF) :-
rename_fresh_vars(R,Num,NumF).
%%%%%%%%%%%
filter_and_check_w(Constr,ConstrAll,Warning) :-
filter_and_check(Constr,ConstrAll,Warning),
mk_warning(Warning).
filter_and_check(C,NewC,W) :-
split_cs(C,RedCS), %split the CS into <neq-constraints,other-constraints>
filter_and_check1(C,RedCS,NewC,W).
filter_and_check1([],_GC,[],_) :- !.
filter_and_check1([C|R],GC,ReducedC,Warning) :- %remove sort constraint not to be shown
type_constr(C),
type_constraints_to_be_shown(LConstr), \+member(C,LConstr),!,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([comp(X,Y,Z)|R],GC,[comp(X,Y,Z)|ReducedC],Warning) :-
nocomp_elim,
var(Warning),
tail(X,TX),tail(Y,TY),tail(Z,TZ),
samevar3(TX,TY,TZ),!,
Warning = unsafe,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([C|R],GC,[C|ReducedC],Warning) :-
noran_elim,
var(Warning),
is_ran_l(C,_,X,Y),var(X),nonvar(Y),!,
Warning = unsafe,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([C|R],GC,[C|ReducedC],Warning) :-
noneq_elim,
var(Warning),
is_neq(C,1,W,T),var(W),var(T),
find_setconstraint(W,T,GC,_X,_Y),!,
Warning = unsafe,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([C|R],GC,[C|ReducedC],Warning) :-
noneq_elim,
var(Warning),
is_neq(C,1,W,T), var(W), aggr_term(T),
find_setconstraint(W,GC),!,
Warning = unsafe,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([X in int(inf,B)|R],GC,[X =< B|ReducedC],Warning) :- !, %replace open domain declarations
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([X in int(A,sup)|R],GC,[X >= A|ReducedC],Warning) :- !, %replace open domain declarations
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([glb_state(Rel)|R],GC,ReducedC,Warning) :- %remove constraints glb_state/1
Rel =.. [_OP,E1,E2], %e.g. glb_state(X>3) & X in int(10,sup)
(ground(E2), get_domain(E1,(E1 in _)),!
;
ground(E1), get_domain(E2,(E2 in _))
),!,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([glb_state(Rel)|R],GC,[Rel|ReducedC],Warning) :- !, %extract C from glb_state(C)
(var(Warning), %and generate warning if C is:
int_solver(clpfd), %e.g X>Y, X>X-1
Rel =.. [_OP,E1,E2], %e.g. X+Y>2
(\+ground(E1),\+ground(E2),!
;
term_variables(Rel,VarsList), VarsList=[_,_|_]
),!,
Warning = 'not_finite_domain'
;
true),!,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([C|R],GC,[C|ReducedC],Warning) :-
(var(Warning),
contains_open_int(C),!,
Warning = 'not_finite_domain'
;
true),!,
filter_and_check1(R,GC,ReducedC,Warning).
filter_and_check1([C|R],GC,[C|ReducedC],Warning) :-
filter_and_check1(R,GC,ReducedC,Warning).
mk_warning(R) :-
var(R),!.
mk_warning('not_finite_domain') :- !,
write('\n***WARNING***: non-finite domain'),nl.
mk_warning(unsafe) :- !,
write('\n***WARNING***: possible unreliable answer'),nl.
contains_open_int(C) :-
C=..[OP,X,Y],!,
(OP == subset,! ; OP == dom), % NOT-SOLVED irreducible constraints which may
(open_intv(X),! ; open_intv(Y)). % contain open intervals
%contains_open_int(C) :-
% C=..[_,X,Y,Z],
% (open_intv(X),! ; open_intv(Y),! ; open_intv(Z)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Using {log} from Prolog %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The following predicates allow a Prolog program to use the
% {log} facilities for set/bag definition and manipulation,
% without leaving the Prolog execution environment.
% In particular, they provide a (Prolog) predicate for calling
% any {log} goal G, possibly involving {log} set constraints.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% setlog(+Goal)
%
setlog(Goal) :-
setlog(Goal,_,_).
%%%% setlog(+Goal,-OutConstraintList)
%
setlog(Goal,OutConstrLst) :-
setlog(Goal,OutConstrLst,_).
%%%% setlog(+Goal,-OutConstraintList,-Res) (Res = success | maybe)
%
setlog(Goal,OutConstrLst,Res) :-
set_default,
setlog1(Goal,OutConstrLst,Res).
setlog1(Goal,OutConstrLst,Res) :-
nonvar(Goal),
copy_term(Goal,NewGoal),
setlog2(NewGoal,Constr,Res),
postproc(Constr,OutConstrLst), %from 'with' to {...} notation
postproc(NewGoal,NewGoal_ext),
postproc(Goal,Goal_ext),
Goal_ext = NewGoal_ext. %apply sustitutions to the original variables
setlog2(NewGoal,Constr,Res) :-
solve(NewGoal,C),
remove_solved(C,C1), %remove info about "solved" constraints
add_intv(C1,Constr1,Warning), %add the possibly remaining interval constr's
filter_and_check(Constr1,Constr,Warning),
map_warning(Warning,Res).
%%%% setlog with timeout and other optional strategies (setlog/5)
%%%% setlog(+Goal,+TimeOut,-OutConstraintList,-Res,+Options) (Res = success | time_out | maybe)
%
setlog(Goal,TimeOut,OutConstrLst,Res,Options) :-
set_default,
setlog1(Goal,TimeOut,OutConstrLst,Res,Options).
setlog1(Goal,TimeOut,OutConstrLst,Res,[]) :- !,
set_default_control,
time_out(setlog1(Goal,OutConstrLst,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlog1(Goal,TimeOut,OutConstrLst,Res,[Opt1|ROpt]) :-
set_default_control,
setlogTimeOut_opt(Opt1,Goal,TimeOut,Constr,Res1),
setlogTimeOut_cont(ROpt,Goal,TimeOut,Constr,OutConstrLst,Res1,Res).
setlogTimeOut_opt(clpq,Goal,TimeOut,Constr,Res) :- !,
int_solver(Current),
ssolve(int_solver(clpq),[],[]),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res),
ssolve(int_solver(Current),[],[]).
setlogTimeOut_opt(clpfd,Goal,TimeOut,Constr,Res) :- !,
int_solver(Current),
ssolve(int_solver(clpfd),[],[]),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res),
ssolve(int_solver(Current),[],[]).
setlogTimeOut_opt(final,Goal,TimeOut,Constr,Res) :- !,
set_final,
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlogTimeOut_opt(noirules,Goal,TimeOut,Constr,Res) :- !,
ssolve(noirules,[],[]),
%time_out(setlog2(Goal,Constr,Res1),TimeOut,Res2),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlogTimeOut_opt(subset_elim,Goal,TimeOut,Constr,Res) :- !,
ssolve(subset_elim,[],[]),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlogTimeOut_opt(noneq_elim,Goal,TimeOut,Constr,Res) :- !,
ssolve(noneq_elim,[],[]),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlogTimeOut_opt(noran_elim,Goal,TimeOut,Constr,Res) :- !,
ssolve(noran_elim,[],[]),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlogTimeOut_opt(nocomp_elim,Goal,TimeOut,Constr,Res) :- !,
ssolve(nocomp_elim,[],[]),
time_out(setlog1(Goal,Constr,Res1),TimeOut,Res2),
check_timeout_res(Res2,Res1,Res).
setlogTimeOut_cont([],_Goal,_TimeOut,_Constr,_OutConstrLst,Return,Return) :- !.
setlogTimeOut_cont(_,_Goal,_TimeOut,_Constr,_OutConstrLst,success,success):- !.
setlogTimeOut_cont(ROpt,Goal,TimeOut,_,OutConstrLst,_,Res) :-
setlog1(Goal,TimeOut,OutConstrLst,Res,ROpt).
%%%% setlog with timeout and default strategies (setlog/4)
%%%% setlog(+Goal,+TimeOut,-OutConstraintList,-Res) (Res = success | time_out | maybe)
%
setlog(Goal,TimeOut,OutConstrLst,Res) :-
setlog5_opts(Opts_list),
setlog(Goal,TimeOut,OutConstrLst,Res,Opts_list).
%%%% setlog_InOut(+Goal,+InConstraintList,-OutConstraintList)
%
setlog_InOut(Goal,InConstrLst,OutConstrLst) :-
nonvar(Goal), nonvar(InConstrLst),
set_default,
list_to_conj(InConstr,InConstrLst), %from list (InConstrLst) to conjunction (InConstr)
conj_append(Goal,InConstr,ExtdGoal),
copy_term(ExtdGoal,NewGoal),
solve(NewGoal,OutCLstIntl),
remove_solved(OutCLstIntl,ROutCLstIntl), %remove info about "solved" constraints
add_intv(ROutCLstIntl,OutFinalCLstIntl,_), %add the possibly remaining interval constr's
postproc(OutFinalCLstIntl,OutConstrLst), %from 'with' to {...} notation
postproc(NewGoal,NewGoal_ext),
postproc(ExtdGoal,ExtdGoal_ext),
ExtdGoal_ext = NewGoal_ext. %apply sustitutions to the original variables
%%%% setlog_InOut_partial(+Goal,+InConstraintList,-OutConstraintList)
%
setlog_InOut_partial(Goal,InConstrLst,OutConstrLst) :-
nonvar(Goal), nonvar(InConstrLst),
set_default,
list_to_conj(InConstr,InConstrLst), %from list (InConstrLst) to conjunction (InConstr)
conj_append(Goal,InConstr,ExtdGoal),
copy_term(ExtdGoal,NewGoal),
transform_goal(NewGoal,B), %from extl to internal repr. (remove SF, RUQ, {...})
solve_goal(B,Constr), %call the constraint solver (in 'non-final' mode)
postproc(Constr,OutConstrLst), %from 'with' to {...} notation
postproc(NewGoal,NewGoal_ext),
postproc(ExtdGoal,ExtdGoal_ext),
ExtdGoal_ext = NewGoal_ext. %apply sustitutions to the original variables
%%%% setlog_InOut_sc(+Constraint,+InConstraintList,-OutConstraintList)
%
setlog_InOut_SC(Constr,InConstrLst,OutConstrLst) :- %to solve {log} Set Constraints (partial solve)
nonvar(Constr), nonvar(InConstrLst),
set_default,
list_to_conj(InConstr,InConstrLst), %from list (InConstrLst) to conjunction (InConstr)
conj_append(Constr,InConstr,CS),
copy_term(CS,NewCS),
preproc_goal(NewCS,NewCSIntl), %from {...} to 'with' notation;
solve_goal(NewCSIntl,OutCLstIntl), %call the constraint solver (in 'non-final' mode)
postproc(OutCLstIntl,OutConstrLst), %from 'with' to {...} notation
postproc(CS,CSExt),
postproc(NewCS,NewCSExt),
CSExt = NewCSExt. %apply sustitutions to the original variables
map_warning(Warning,maybe) :-
nonvar(Warning),Warning == 'not_finite_domain',!.
map_warning(Warning,maybe) :-
nonvar(Warning),Warning == 'unsafe',!.
map_warning(Warning,maybe) :-
nonvar(Warning),Warning == 'maybe',!.
map_warning(_Warning,success).
check_timeout_res(success,Solve_res,Res) :- !,
map_warning(Solve_res,Res).
check_timeout_res(timeout,_,timeout).
check_timeout_res(Timeout_Res,_,Timeout_Res).
%not_save(success,maybe) :- !.
%not_save(Res,Res) :- !.
%%%% other predicates for Prolog to {log} interface
setlog_consult(File) :- %like setlog(consult(File))
setlog(consult(File,mute),_). %but no message is sent to the std output
setlog_clause(Clause) :- %for compatibility with previous versions
setlog(assert(Clause),_).
consult_lib :- %to consult the {log} library file
setlog(consult_lib,_).
setlog_config(ConfigParams) :- %to modify {log}'s configuration parameters
set_params(ConfigParams).
setlog_rw_rules :- %to load the filtering rule library
rw_rules(Lib),
mk_file_name(Lib,FullName),
consult(FullName).
%%%% auxiliary predicates for Prolog to {log} interface
remove_solved([],[]).
remove_solved([solved(C,_,_,_)|R],[C|RR]) :- !,
remove_solved(R,RR).
remove_solved([delay(irreducible(C)&true,_)|R],[irreducible(C)|RR]) :- !,
remove_solved(R,RR).
remove_solved([C|R],[C|RR]) :-
remove_solved(R,RR).
set_params([]).
set_params([P1|ParamsList]) :-
apply_params(P1),
set_params(ParamsList).
apply_params(strategy(Str)) :- !,
replace_unitCl(strategy(_),Str).
apply_params(path(Path)) :- !,
replace_unitCl(path(_),Path).
apply_params(rw_rules(FileName)) :- !,
replace_unitCl(rw_rules(_),FileName).
apply_params(fd_labeling_strategy(Str)) :- !,
replace_unitCl(fd_labeling_strategy(_),Str).
%%% to be continued
replace_unitCl(Cl,NewParm) :-
retract(Cl),!,
Cl =.. [F,_X], NewCl =.. [F,NewParm],
assert(NewCl).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% The help sub-system %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setlog_help :- h(setlog).
h(setlog) :-
nl,
write(' - h(syntax), h(constraints), h(builtins), h(lib), h(prolog) to get help '), nl,
write(' information (resp., about: {log} syntactic convenctions, {log} constraints, '), nl,
write(' {log} built-in predicates, {log} library predicates, Prolog predicates'), nl,
write(' for accessing {log})'), nl,
write(' - h(all) to get all available help information'), nl,
write(' - setlog/0: to enter the {log} interactive environment'),nl.
h(all) :-
h(syntax),
h(constraints),
h(builtins),
h(prolog),
h(lib).
h(syntax) :-
nl,
write('%%%%%%%%% Syntactic differences w.r.t. std Prolog %%%%%%%%%'),
nl, nl,
write(' - ''&'' is used in place of '','' in clause bodies'), nl,
write(' - ''or'' is used in place of '';'''),
write(' to represent goal disjunction.'), nl,
write(' - neg or naf are used in place of ''\\+'''),
write(' to represent negation (resp., '), nl,
write(' simplified Constructive Negation and Negation as Failure)'),
nl,
write(' - Interpreted terms.'),
nl,
write(' 1. Extensional sets:'), nl,
write(' (a, b, c: any term; R: variable, set, interval, IS, RIS, CP)'), nl,
write(' - {}: the empty set/multiset'), nl,
write(' - {a,b,c}: the set containing three elements, a, b, c'),nl,
write(' - {a,b/R}: the set {a,b} U R,'), nl,
write(' 2. Extensional multisets:'), nl,
write(' (a, b, c: any term; R: variable, multiset)'), nl,
write(' - *({a,b,b}) (or, * {a,b,b}): the multiset containing the elements,'),nl,
write(' ''a'' (1 occurrence) and ''b'' (2 occurrences)'),nl,
write(' - *({a,b/R}): the multiset *({a,b}) U R'), nl,
write(' 3. Intervals:'), nl,
write(' (h, k: variable, integer number)'), nl,
write(' - int(h,k): the set of'), nl,
write(' integer numbers ranging from h to k (k>=h) or the empty set (k<h)'), nl,
write(' 4. Cartesian Products (CP):'), nl,
write(' (A, B: variable, set, IS)'), nl,
write(' - cp(A,B): the set {[x,y] : x in A & y in B}'), nl,
write(' 5. Intensional Sets (IS):'), nl,
write(' (X: variable; G: any {log} goal containing X)'), nl,
write(' - {X : G}'), nl,
write(' - {X : exists(V,G)}, V variable local to G'), nl,
write(' - {X : exists([V1,...,Vn],G)}, '), nl,
write(' V1,...,Vn variables local to G'), nl,
write(' 6. Restricted Intensional Sets (RIS):'), nl,
write(' - ris(C in D,[V1,...,Vn],G,t,aux) ([V1,...,Vn], aux optional): '), nl,
write(' the set {Y : exists([C,V1,...,Vn],C in D & G & Y=t & aux)}'), nl,
write(' - ris(C in D,[V1,...,Vn],G) ([V1,...,Vn] optional): '), nl,
write(' the set {Y : exists([C,V1,...,Vn],C in D & G & Y=X)}'), nl,
write(' C (control term): X, [X,Y], {X/Y}, '), nl,
write(' D (domain): variable, set, interval, RIS, CP, '), nl,
write(' V1,...,Vn: variables local to G, '), nl,
write(' G: any {log} goal, '), nl,
write(' t (pattern): any term but not a RIS, '), nl,
write(' aux (auxiliary predicates for t): any {log} goal (e.g. t: [X,Y], aux: Y is X+1)'), nl,
write(' - Special atoms.'),
nl,
write(' 1. Restricted Universal Quantifiers (RUQ): '), nl,
write(' (A: variable, set, multiset, list, interval, IS)'), nl,
write(' - forall(X in A, G),'), nl,
write(' X variable and G any {log} goal containing X'), nl,
write(' - forall(X in A, exists(V,G)),'),nl,
write(' - forall(X in A, exists([V1,...,Vn],G)),'), nl,
write(' V1,...,Vn variables local to G'), nl,
nl.
h(constraints) :-
nl,
write('%%%%%%%%% {log} constraints %%%%%%%%%'),
nl, nl,
write(' 1. General constraints:'), nl,
write(' (u: any term; t: any term but not a CP nor a RIS; '), nl,
write(' A: variable, set, multiset, list, interval, CP, IS, RIS)'), nl,
write(' - u1 = u2 (equality)'), nl,
write(' - u1 neq u2 (non-equality)'), nl,
write(' - t in A (membership)'), nl,
write(' - t nin A (non-membership)'), nl,
nl,
write(' 2. Set constraints:'), nl,
write(' (A, B, C: variable, set, interval, IS, CP) '), nl,
write(' - un(A,B,C)/nun(A,B,C) (union/not-union)'), nl,
write(' - disj(A,B)/ndisj(A,B) (disjointness/non-disjointness)'), nl,
write(' - inters(A,B,C)/ninters(A,B,C) (intersection/not-intersection)'), nl,
write(' - subset(A,B)/nsubset(A,B) (subset/not-subset)'), nl,
write(' - ssubset(A,B) (strict subset)'), nl,
write(' - diff(A,B,C)/ndiff(A,B,C) (difference/not-difference)'), nl,
write(' - sdiff(A,B,C) (symmetric difference)'), nl,
write(' - less(A,t,B) (element removal; t any term)'), nl,
write(' (D: variable, set, interval, IS; '), nl,
write(' Aint: variable, interval, set or IS of non-negative integers; '), nl,
write(' n: variable, integer constant)'), nl,
write(' - size(D,n) (cardinality)'), nl,
write(' - sum(Aint,n) (sum all elements (non-negative integers only))'), nl,
write(' - smin(Aint,n) (minimum element)'), nl,
write(' - smax(Aint,n) (maximum element)'), nl,
write(' (u: any term) '), nl,
write(' - set(u)/nset(u) (u is/is_not a set)'), nl,
write(' - pair(u)/npair(u) (u is/s_not a pair)'), nl,
write(' - bag(u) (u is a multiset)'), nl,
write(' - list(u) (u is a list)'), nl,
nl,
write(' 3. Integer constraints:'), nl,
write(' (e: integer expression; n: variable or integer constant)'), nl,
write(' - n is e1 (equality - with evaluation of expression e)'), nl,
write(' - e1 =< e2 (less or equal), e1 < e2 (less)'), nl,
write(' - e1 >= e2 (greater or equal), e1 > e2 (greater)'), nl,
write(' - e1 =:= e2 (equal), e1 =\\= e2 (not equal)'), nl,
write(' - integer(n)/ninteger(n) (n isis_not an integer number)'), nl,
nl,
write(' 4. Binary relation and partial function constraints:'), nl,
write(' (A: variable, set, interval, IS, CP; R, RR: variable, binary relation, CP) '), nl,
write(' - dom(R,A)/ndom(R,A) (domain/not-domain)'), nl,
write(' - inv(R,RR)/ninv(R,RR) (inverse/not-inverse)'), nl,
write(' (S: variable, binary relation) '), nl,
write(' - ran(S,A)/nran(S,A) (range/not-range)'), nl,
write(' - comp(S1,S2,S3)/ncomp(S1,S2,S3) (composition/not-composition)'), nl,
write(' (B: variable, set, IS) '), nl,
write(' - id(B,S) (identity relation)'), nl,
write(' - dres(B,S1,S2) (domain restriction)'), nl,
write(' - rres(S1,B,S2) (range restriction)'), nl,
write(' - dares(B,S1,S2) domain anti-restriction)'), nl,
write(' - rares(S1,B,S2) (range anti-restriction)'), nl,
write(' - rimg(S,B1,B2) (relational image)'), nl,
write(' - oplus(S1,S2,S3) (overriding)'), nl,
write(' (F: variable, partial function; t: any term but not a CP nor a RIS) '), nl,
write(' - apply(F,t1,t2) (function application)'), nl,
write(' (u: any term) '), nl,
write(' - rel(u)/nrel(u) (u is/is_not a binary relation)'), nl,
write(' - pfun(u)/npfun(u)(u is/is_not a partial function)'), nl,
nl.
h(builtins) :-
h(sbuilt),
h(pbuilt).
h(sbuilt) :-
nl,
write('%%%%%%%%% {log} specific built-in predicates %%%%%%%%%'),
nl, nl,
write(' - halt/0: to leave the {log} interactive environment'),
write(' (go back to the host environment) '), nl,
write(' - help/0: to get general help information about {log}'), nl,
write(' - prolog_call(G): to call any Prolog goal G from {log}'),nl,
write(' - call(G), call(G,C): to call a {log} goal G, possibly getting constraint C'),nl,
write(' - solve(G): like call(G) but all constraints generated by G are immediately solved'),nl,
write(' - consult_lib/0: to consult the {log} library file setloglib.slog'),nl,
write(' - add_lib(F): to add any file F to the {log} library '),nl,
write(' - G!: to make a {log} goal G deterministic'), nl,
write(' - delay(G,C), G, C {log} goals: to delay execution of G '),nl,
write(' until either C holds or the computation ends; '), nl,
write(' - delay(irreducible(G),C), G, C {log} goals: to delay execution of G '),nl,
write(' until C holds; otherwise return irreducible(G)'), nl,
write(' - labeling(X): to force labeling for the domain variable X'),nl,
write(' - strategy(S): to change goal atom selection strategy to S'),nl,
write(' (S: cfirst, ordered, cfirst(list_of_atoms))'), nl,
write(' - noirules/0, irules/0: to deactivate/activate inference rules '),nl,
write(' (default: irules)'), nl,
write(' - nolabel/0, label/0: to deactivate/activate labeling on integer variables'),nl,
write(' (default: label; possible unreliable solutions when nolabel)'), nl,
write(' - noneq_elim/0, neq_elim/0: to deactivate/activate elimination of neq-'),nl,
write(' constraints (default: neq_elim; possible unreliable solutions when noneq_elim)'), nl,
write(' - noran_elim/0, ran_elim/0: to deactivate/activate elimination of ran-'),nl,
write(' constraints of the form ran(R,{...})'), nl,
write(' (default: ran_elim; possible unreliable solutions when noran_elim)'), nl,
write(' - notrace/0, trace(Mode): to deactivate/activate constraint solving tracing; '),nl,
write(' Mode=sat: general, Mode=irules: inference rules only (default: notrace)'), nl,
write(' - time(G,T): to get CPU time (in milliseconds) for solving goal G'),
nl.
h(pbuilt) :-
nl,
write('%%%%%%%% Prolog-like built-in predicates (redefined in {log} %%%%%%%%'),
nl, nl,
write_built_list,
write(' - read/1'),nl,
write(' - write/1'),nl,
write(' - call/1'),nl,
write(' - assert/1'),nl,
write(' - consult/1'),nl,
write(' - listing/0'),nl,
write(' - abolish/0'),nl.
h(lib) :-
nl,
write('%%%%%%%% {log} library %%%%%%%%'), nl, nl,
check_lib,
nl.
h(prolog) :-
nl,
write('%%%%%%%% Prolog predicates for accessing {log} facilities %%%%%%%%%'),
nl,nl,
write(' - setlog/0: to enter the {log} interactive environment'),nl,
write(' - setlog(G), setlog(G,C): to call a {log} goal G, '), nl,
write(' possibly getting an (output) {log} constraint C'), nl,
write(' - setlog_InOut(G,InCLst,OutCLst), setlog_InOut_partial(G,InCLst,OutCLst), '), nl,
write(' setlog_InOut_sc(C,InCLst,OutCLst): to solve a {log} goal G / constraint C '), nl,
write(' with a (possibly empty) input constraint list InCLst '), nl,
write(' and output constraint list OutCLst '), nl,
write(' - setlog_consult(F): to consult a {log} file F '),nl,
write(' - consult_lib: to consult the {log} library file '),nl,
write(' - setlog_clause(Cl): to add a {log} clause Cl to the current {log} program '),nl,
write(' - setlog_config(list_of_params): to modify {log} configuration parameters '),nl,
write(' (parameters: strategy(S), path(Path), rw_rules(File))'), nl,
write(' - setlog_rw_rules: to load the filtering rule library'),
nl.
write_built_list :-
sys(N,Ar),
write(' - '),write(N),write('/'),write(Ar),nl,
fail.
write_built_list.
check_lib :-
solve(setlog_lib_help,_),!.
check_lib :-
write('{log} library predicates not available'),nl,
write('Type consult_lib to load the {log} library '),nl.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% The inference engine %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% solve(+Goal,-Constraint) Goal: {log} goal in external form
%
solve(Goal_int_ruq,Constr):-
transform_goal(Goal_int_ruq,GoalNew),
%DBG% nl,write('NEW GOAL: '),write(GoalNew),nl,
solve_goal_fin(GoalNew,Constr).
%%%% solve_goal_fin(+Goal,-Constraint) Goal: {log} goal in internal form
%
solve_goal_fin(G,ClistNew) :-
constrlist(G,GClist,GAlist),
solve_goal_fin_constr(GClist,GAlist,ClistNew).
solve_goal_fin_constr(GClist,GAlist,ClistNew):-
solve_goal_constr(GClist,GAlist,Clist),
final_sat(Clist,ClistNew).
%%%% solve_goal(+Goal,-Constraint) Goal: {log} goal in internal form
%
solve_goal(true,[]) :- !.
solve_goal(false,_) :- !,fail.
solve_goal(G,ClistNew) :-
constrlist(G,GClist,GAlist),
solve_goal_constr(GClist,GAlist,ClistNew).
%%%% solve_goal_constr(+Constraint,+Non_Constraint,-Constraint)
%
solve_goal_constr(Clist,[],CListCan):- !,
sat(Clist,CListCan,nf).
solve_goal_constr(Clist,[true],CListCan):- !,
sat(Clist,CListCan,nf).
solve_goal_constr(Clist,[A|B],CListOut):-
sat(Clist,ClistSolved,nf),
sat_or_solve(A,ClistSolved,ClistNew,AlistCl,nf),
append(AlistCl,B,AlistNew),
solve_goal_constr(ClistNew,AlistNew,CListOut).
sat_or_solve(A,Clist_in,Clist_out,[],F) :-
atomic_constr(A),!,
sat([A|Clist_in],Clist_out,F).
sat_or_solve(A,Clist_in,Clist_out,Alist_out,_) :-
ssolve(A,ClistCl,Alist_out),
append(Clist_in,ClistCl,Clist_out).
%%%% ssolve(+Atom,-Constraint,-Non_Constraint)
%
ssolve(true,[],[]):- !. %% unit goal
ssolve(neg A,ClistNew,[]):- %% simplified constructive negation
!,c_negate(A,ClistNew).
ssolve(naf A,ClistNew,[]):- %% negation as failure
!,naf_negate(A,ClistNew).
ssolve((G1 or G2),ClistNew,[]):- !, %% goal disjunction
(solve_goal(G1,ClistNew)
;
solve_goal(G2,ClistNew)
).
ssolve(call(A),C,[]):- %% meta call
!,solve_goal(A,C).
ssolve(call(A,C),C,[]):- %% meta call
!,solve_goal(A,C).
ssolve(solve(A),C,[]):- %% forces goal A to be completely solved
!,solve_goal_fin(A,C).
ssolve((A)!,C,[]):- %% deterministic call
!,solve_goal(A,C),!.
ssolve(add(A),C,[]):- %% add the constraint A to the constraint store (without solving it)
!, list_to_conj(A,C).
ssolve(ruq_call(S,InName,VarList),Cout,[]) :- !, %% RUQs
solve_RUQ(S,InName,VarList,[],Cout).
ssolve(sf_call(S,GName,PName,VarList),Cout,[]) :- !, %% SF
solve_SF(S,GName,PName,VarList,[],Cout).
ssolve(prolog_call(A),[],[]):- %% Prolog call (any predicate)
nonvar(A),!,A.
ssolve(A,[],[]):- %% {log} built-in predicates inherited from Prolog
nonvar(A),functor(A,F,N),
sys(F,N),!,A.
ssolve(A,C,[]):- %% {log} specific built-in predicates
sys_special(A,C),!.
ssolve(labeling(X),[],[]):- %% explicit labeling for integer variables
nonvar(X),!.
ssolve(labeling(X),[],[]):- !,
labeling(X).
ssolve(label,[],[]):- !, %% (re-)activate automatic labeling
cond_retract(nolabel).
ssolve(nolabel,[],[]):- %% deactivate automatic labeling
nolabel,!.
ssolve(nolabel,[],[]):- !,
assert(nolabel).
ssolve(notrace,[],[]):- !, %% deactivate constraint solving tracing
retract_trace.
ssolve(trace(sat),[],[]):- %% activate constraint solving tracing
trace(sat),!.
ssolve(trace(irules),[],[]):-
trace(irules),!.
ssolve(trace(Mode),[],[]):- !,
(Mode==sat,! ; Mode==irules),
assert(trace(Mode)).
ssolve(neq_elim,[],[]):- !, %% (re-)activate automatic neq elimination
cond_retract(noneq_elim).
ssolve(noneq_elim,[],[]):- %% deactivate automatic neq elimination
noneq_elim,!.
ssolve(noneq_elim,[],[]):- !,
assert(noneq_elim).
ssolve(ran_elim,[],[]):- !, %% (re-)activate automatic ran elimination
cond_retract(noran_elim).
ssolve(noran_elim,[],[]):- %% deactivate automatic ran elimination
noran_elim,!.
ssolve(noran_elim,[],[]):- !,
assert(noran_elim).
ssolve(comp_elim,[],[]):- !, %% (re-)activate automatic comp elimination
cond_retract(nocomp_elim).
ssolve(nocomp_elim,[],[]):- %% deactivate automatic comp elimination
nocomp_elim,!.
ssolve(nocomp_elim,[],[]):- !,
assert(nocomp_elim).
ssolve(irules,[],[]):- !, %% (re-)activate automatic application of inference rules
cond_retract(noirules).
ssolve(noirules,[],[]):- %% deactivate automatic application of inference rules
noirules,!.
ssolve(noirules,[],[]):- !,
assert(noirules).
ssolve(strategy(Str),[],[]):- !, %% change goal atom selection strategy
retract(strategy(_)),
assert(strategy(Str)).
ssolve(int_solver(Slv),[],[]):- %% get the current integer solver
var(Slv),!,
int_solver(Slv).