导致错误的原因是“ _14804 $ = sum([]([](_ 13405 {[0,1]},......]中的实例化错误”?

时间:2019-05-04 05:30:08

标签: eclipse-clp

以下程序是该程序的实现:

How to implement these Sigma notations in ECLIPSE-CLP or Prolog

我不知道是什么错误,或者我怎么能写得更好?

使用ECLISPE-CLP的IC库

 :-lib(ic).

go:- vars(CustomerNo_N ,Distaces_c , CustomersDemand_d ,VehicleCapacity_C , MaxDistanceForVehicles_D) ,
    constraints( CustomerNo_N,Distaces_c , CustomersDemand_d , VehicleCapacity_C , MaxDistanceForVehicles_D ,X,Y),
    object( Distaces_c ,X,Obj),
    %minimize(labeling([Obj,CustomerNo_N,Distaces_c , CustomersDemand_d , VehicleCapacity_C , MaxDistanceForVehicles_D ,X,Y]),0.1),
    minimize(labeling([Obj]),0.1),
    %minimize(search(Obj,0,first_fail,indomain,complete,[]),MinObj),

    write(Minobj)   .
%*********************************

这是实现对象表示法:

object(CustomerNo_N, Distaces_c ,X,Obj) :-
            N is CustomerNo_N ,
            C is Distaces_c,
            ( multifor([I,J],1,N), foreach(Term,Terms), param(C,X) do
                    Term = (C[I,J] * sum(X[I,J,*]))
            ),
            Obj = sum(Terms).
    %*********************************

常数常量:

vars(CustomerNo_N ,Distaces_c , CustomersDemand_d ,VehicleCapacity_C , MaxDistanceForVehicles_D):-

    CustomerNo_N is 8,    
    CustomersDemand_d=[](4,1,5,2,2,4,3),  

    VehicleCapacity_C=[](3,3,4,4,4,3,3,4),  

    MaxDistanceForVehicles_D=[](10,8,9,5,7,9,7,8), 

    Distaces_c =[]([]( 0, _5, _3, _2, _6, _4, _1, _5),   
                  []( _5, _0, _4, _3, _7, _6, _4, _6),
                  []( _3, _4, _0, _2, _1, _3, _8, _3),
                  []( _2, _3, _2, _0, _5, _7, _2, _3),
                  []( _6, _7, _1, _5, _0, _7, _1, _4),
                  []( _4, _6, _3, _7, _7, _0, _8, _7),
                  []( _1, _4, _8, _2, _1, _8, _0, _2),
                  []( _5, _6, _3, _3, _4, _7, _2, _0)
               ).

%*********************************

所有6个约束的实施或受以下条件约束:

constraints( CustomerNo_N,Distaces_c , 
                    CustomersDemand_d ,
                    VehicleCapacity_C , 
                    MaxDistanceForVehicles_D ,X,Y
                    ) :-

                    dim(X,[CustomerNo_N,CustomerNo_N,CustomerNo_N]), %Xij become 1 when visited 
                    X #::[0..1],            


                dim(Y,[CustomerNo_N,CustomerNo_N]),  %Yij become 1 when customer i get serviced by vehicle j
                %Y[CustomerNo_N,CustomerNo_N] #::[0..1,0..1],   
                Y #::[0..1],


            % Const 1
            ( for(K,1,CustomerNo_N),
                for(I,1,CustomerNo_N), 
                param(Y) do
                sum(Y[I,K]) $= 1
            )

            ,
            % Const 2           
            ( for(K,1,CustomerNo_N), param(Y) do
                sum(Y[0,K]) $= K
            ),      
            % Const 3
            (
                multifor([I,J],1,CustomerNo_N) ,
                param(X,Y) do
                    sum(X[I,J,*]) $= Y[I,*] , J #>I
            ),  
            % Const 4
            (
                for(K,1,CustomerNo_N), 
                param(CustomersDemand_d,Y,VehicleCapacity_C) do
                    sum(CustomersDemand_d[K]*Y[*,K]) $=< VehicleCapacity_C[K]

            ),  
            % Const 5
            (
                multifor([I,J,K],1,CustomerNo_N), 
                param(Distaces_c,X,MaxDistanceForVehicles_D) do
                    sum(Distaces_c[I,J]*X[I,J,K]) $=< MaxDistanceForVehicles_D[K]

            ),  

            S is CustomerNo_N,
            S $>=2 ,

            % Const 6

            (
                multifor([I,J,K],1,CustomerNo_N), 
                    param(X,S) do
                        sum(X[I,J,K]) $=< S -1

            )



            .   

谢谢。

0 个答案:

没有答案