一个关于用lingo解二次规划限制条件的问题
model:data:H=@file('imageinfo.txt');W=@file('imageinfo.txt');r=@file('imageinfo.txt')...
model:
data:
H=@file('imageinfo.txt');
W=@file('imageinfo.txt');
r=@file('imageinfo.txt');
c=@file('imageinfo.txt');
height=@file('imageinfo.txt');
width=@file('imageinfo.txt');
Du=0;
enddata
sets:
coordinate:x,y;
rows/1..H/;
cols/1..W/;
rr/1..r/;
cc/1..c/;
!salient(rows,cols):saliency;
mesh(rr,cc):mesh_x,mesh_y,grid_x,grid_y,newmesh_x,newmesh_y,saliency;
endsets
data:
saliency=@file('saliency.txt');
mesh_x=@file('coordinate_x.txt');
mesh_y=@file('coordinate_y.txt');
grid_x=@file('grid_x.txt');
grid_y=@file('grid_y.txt');
@text('result_x.txt')=newmesh_x;
@text('result_y.txt')=newmesh_y;
enddata
@for(mesh(I,J) | mesh_x(I,J) #ne# -1:newmesh_x(I,J)=mesh_x(I,J));
@for(mesh(I,J) | mesh_y(I,J) #ne# -1:newmesh_y(I,J)=mesh_y(I,J));
!目标函数;
min=@sum(mesh(I,J) | (I #le# H) #and# (J #le#W): (saliency(I,J)+0.2)*(
( (newmesh_x(I,J)-newmesh_x(I,J+1) ) - (grid_x(I,J)-grid_x(I,J+1) ) )^2+( (newmesh_y(I,J)-newmesh_y(I,J+1) ) - (grid_y(I,J)-grid_y(I,J+1) ) )^2+
( (newmesh_x(I,J+1)-newmesh_x(I+1,J+1) ) - (grid_x(I,J+1)-grid_x(I+1,J+1) ) )^2+( (newmesh_y(I,J+1)-newmesh_y(I+1,J+1) ) - (grid_y(I,J+1)-grid_y(I+1,J+1) ) )^2+
( (newmesh_x(I+1,J+1)-newmesh_x(I+1,J) ) - (grid_x(I+1,J+1)-grid_x(I+1,J) ) )^2+( (newmesh_y(I+1,J+1)-newmesh_y(I+1,J) ) - (grid_y(I+1,J+1)-grid_y(I+1,J) ) )^2+
( (newmesh_x(I+1,J)-newmesh_x(I,J) ) - (grid_x(I+1,J)-grid_x(I,J) ) )^2+( (newmesh_y(I+1,J)-newmesh_y(I,J)) - (grid_y(I+1,J)-grid_y(I,J) ) )^2));
!需求约束;
@for(mesh(I,J):
@gin(newmesh_x(I,J));
@gin(newmesh_y(I,J)));
@for(mesh(I,J) | J #le# W: newmesh_x(I,J)+1 < newmesh_x(I,J+1));
@for(mesh(I,J) | I #le# H: newmesh_y(I,J)+1 <newmesh_y(I+1,J));
@for(mesh(I,J) | J#eq# 1 : newmesh_x(I,J)=0);
@for(mesh(I,J) | J #eq# c : newmesh_x(I,J)=width);
@for(mesh(I,J) | I #eq# 1 : newmesh_y(I,J)=0);
@for(mesh(I,J) | I #eq# r : newmesh_y(I,J)=height);
我运行过很多次,在上面的程序中只有注销掉限制条件
@for(mesh(I,J) | mesh_x(I,J) #ne# -1:newmesh_x(I,J)=mesh_x(I,J));
@for(mesh(I,J) | mesh_y(I,J) #ne# -1:newmesh_y(I,J)=mesh_y(I,J));
才能算出正确的结果,但我的模型里这两个限制条件是必须的,请高手指点一下问题出在哪里?
这个问题对我非常重要,一篇文章的核心算法,就是固定一个网格内部分点的坐标,求解其他点的坐标,但运行时间非常长。可否赐教问题出在哪? 展开
data:
H=@file('imageinfo.txt');
W=@file('imageinfo.txt');
r=@file('imageinfo.txt');
c=@file('imageinfo.txt');
height=@file('imageinfo.txt');
width=@file('imageinfo.txt');
Du=0;
enddata
sets:
coordinate:x,y;
rows/1..H/;
cols/1..W/;
rr/1..r/;
cc/1..c/;
!salient(rows,cols):saliency;
mesh(rr,cc):mesh_x,mesh_y,grid_x,grid_y,newmesh_x,newmesh_y,saliency;
endsets
data:
saliency=@file('saliency.txt');
mesh_x=@file('coordinate_x.txt');
mesh_y=@file('coordinate_y.txt');
grid_x=@file('grid_x.txt');
grid_y=@file('grid_y.txt');
@text('result_x.txt')=newmesh_x;
@text('result_y.txt')=newmesh_y;
enddata
@for(mesh(I,J) | mesh_x(I,J) #ne# -1:newmesh_x(I,J)=mesh_x(I,J));
@for(mesh(I,J) | mesh_y(I,J) #ne# -1:newmesh_y(I,J)=mesh_y(I,J));
!目标函数;
min=@sum(mesh(I,J) | (I #le# H) #and# (J #le#W): (saliency(I,J)+0.2)*(
( (newmesh_x(I,J)-newmesh_x(I,J+1) ) - (grid_x(I,J)-grid_x(I,J+1) ) )^2+( (newmesh_y(I,J)-newmesh_y(I,J+1) ) - (grid_y(I,J)-grid_y(I,J+1) ) )^2+
( (newmesh_x(I,J+1)-newmesh_x(I+1,J+1) ) - (grid_x(I,J+1)-grid_x(I+1,J+1) ) )^2+( (newmesh_y(I,J+1)-newmesh_y(I+1,J+1) ) - (grid_y(I,J+1)-grid_y(I+1,J+1) ) )^2+
( (newmesh_x(I+1,J+1)-newmesh_x(I+1,J) ) - (grid_x(I+1,J+1)-grid_x(I+1,J) ) )^2+( (newmesh_y(I+1,J+1)-newmesh_y(I+1,J) ) - (grid_y(I+1,J+1)-grid_y(I+1,J) ) )^2+
( (newmesh_x(I+1,J)-newmesh_x(I,J) ) - (grid_x(I+1,J)-grid_x(I,J) ) )^2+( (newmesh_y(I+1,J)-newmesh_y(I,J)) - (grid_y(I+1,J)-grid_y(I,J) ) )^2));
!需求约束;
@for(mesh(I,J):
@gin(newmesh_x(I,J));
@gin(newmesh_y(I,J)));
@for(mesh(I,J) | J #le# W: newmesh_x(I,J)+1 < newmesh_x(I,J+1));
@for(mesh(I,J) | I #le# H: newmesh_y(I,J)+1 <newmesh_y(I+1,J));
@for(mesh(I,J) | J#eq# 1 : newmesh_x(I,J)=0);
@for(mesh(I,J) | J #eq# c : newmesh_x(I,J)=width);
@for(mesh(I,J) | I #eq# 1 : newmesh_y(I,J)=0);
@for(mesh(I,J) | I #eq# r : newmesh_y(I,J)=height);
我运行过很多次,在上面的程序中只有注销掉限制条件
@for(mesh(I,J) | mesh_x(I,J) #ne# -1:newmesh_x(I,J)=mesh_x(I,J));
@for(mesh(I,J) | mesh_y(I,J) #ne# -1:newmesh_y(I,J)=mesh_y(I,J));
才能算出正确的结果,但我的模型里这两个限制条件是必须的,请高手指点一下问题出在哪里?
这个问题对我非常重要,一篇文章的核心算法,就是固定一个网格内部分点的坐标,求解其他点的坐标,但运行时间非常长。可否赐教问题出在哪? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询