人工智能中约束满足问题CSP
p=<x,c>
x = { x1,x2.....}表示n个变量x的集合
c={c1,c2...} 表示n个约束的集合
ci 为满足约束条件的x的取值集合
求解约束满足问题p,就是c的自然连接的结果
在老师的讲解下,稍微理解了一点,
一下用四皇后问题作为例子:希望需要的人可以参考一下
use master;
if db_id('fourQueen') is not null
drop database fourQueen;
go
create database fourQueen;
go
use fourQueen;
--创建变量取值范围表
create table Value(
row int
);
insert into Value values(1),(2),(3),(4);
--约束1第一行对第二行的约数
create table FirToSec(
fir int,
sec int
);
insert into FirToSec select a.row,b.row from Value a,Value b where a.row - b.row not in(0,1,-1);
--约数2第一行对第三行的约数
create table FirToThi(
fir int,
thi int
);
insert into FirToThi select a.row,b.row from Value a,Value b where a.row - b.row not in(0,2,-2);
--约数3第一行对第四行的约数
create table FirToFou(
fir int,
fou int
);
insert into FirToFou select a.row,b.row from Value a,Value b where a.row - b.row not in(0,3,-3);
--约数4第二行对第三行的约数
create table SecToThi(
sec int,
thi int
);
insert into SecToThi select a.row,b.row from Value a,Value b where a.row - b.row not in(0,1,-1);
--约数5第二行对第三行的约数
create table SecToFou(
sec int,
fou int
);
insert into SecToFou select a.row,b.row from Value a,Value b where a.row - b.row not in(0,2,-3);
--约数6第三行对第四行的约数
create table ThiToFou(
thi int,
Fou int
);
insert into ThiToFou select a.row,b.row from Value a,Value b where a.row - b.row not in(0,1,-1);
--求解的自然连接
select x1.fir,x1.sec,x6.thi,x6.Fou from FirToSec x1,FirToThi x2,FirToFou x3,SecToThi x4,SecToFou x5,ThiToFou x6
where x1.fir = x2.fir and x1.fir = x3.fir
and x1.sec = x4.sec and x1.sec = x5.sec
and x2.thi = x4.thi and x2.thi = x6.thi
and x3.fou = x5.fou and x3.fou = x6.Fou;