The Following program is Implementations of this:

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

I dont know what error is or How can I write better?

Using IC Lib of ECLISPE-CLP

 :-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)   .
%*********************************

this is Implementing Object Notation:

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).
    %*********************************

Constant Variables for Sigmas:

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)
               ).

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

Implementation of All 6 Constraints or Subject to:

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

            )



            .   

Thank you.

0 Answers