Adjacency constraint

157 views
Skip to first unread message

Bahadır ECE

unread,
Dec 22, 2014, 1:18:41 PM12/22/14
to ai...@googlegroups.com
Hello,
As a new beginner I am not very experienced in AIMMS.So I thought one can help me from here.

I have 20 facilities to be located to 20 locations. Every facility(i) should be allocated to 1 place and each location(j or l) should be fulled. I also need some to be adjacent to each other. I have written the variable for assignment(i,j) and 2 necessary constraints as shown:

Set Facilities {
        Index: i, h;
        Definition: {
            data
                { 'Facility 1' , 'Facility 2' , 'Facility 3' , 'Facility 4' , 'Facility 5' , 'Facility 6' , 'Facility 7' , 'Facility 8' ,
                  'Facility 9' , 'Facility 10', 'Facility 11', 'Facility 12', 'Facility 13', 'Facility 14', 'Facility 15', 'Facility 16',
                  'Facility 17', 'Facility 18', 'Facility 19', 'Facility 20' }
        }
    }
    Set Locations {
        Index: j, l;
        Definition: {
            data
                { 'Location 1', 'Location 2', 'Location 3', 'Location 4', 'Location 5', 'Location 6', 'Location 7', 'Location 8', 'Location 9',
                  Location10  , Location11  , Location12  , Location13  , Location14  , Location15  , Location16  , Location17  , Location18  ,
                  Location19  , Location20  }
        }
Variable Assignment {
        IndexDomain: (i,j);
        Range: binary;
    }
    Constraint Loc_Constraint {
        IndexDomain: i;
        Definition: sum(j, Assignment(i,j))=1;
    }
    Constraint Fac_Constraint {
        IndexDomain: j;
        Definition: sum(i, Assignment(i,j))=1;

But for adjacency; I have written the constraint below for facility2 and facility3 which should be adjacent:

Constraint Distance_F2_F3 {
        IndexDomain: (j,l);
        Definition: {
            if [Assignment('facility 2',j)=1 and Assignment('facility 3',l)=1] then
            125<= [Assignment('facility 2',j)*Assignment('facility 3',l)*Distance_Locs(j,l)] and
             [Assignment('facility 2',j)*Assignment('facility 3',l)*Distance_Locs(j,l)]<=200
            endif;
        }

Because locations have 125m horizontal distance and 200m vertical distance between each other. And I want them to be next to each other. I have also determined location distances as:
Parameter Distance_Locs {
        IndexDomain: (j,l);
        Definition: {
            data
            { ( 'Location 1', 'Location 2' ) :  125,  ( 'Location 1', 'Location 3' ) :  250,  ( 'Location 1', 'Location 4' ) :  375,
              ( 'Location 1', 'Location 5' ) :  200,  ( 'Location 1', 'Location 6' ) :  325,  ( 'Location 1', 'Location 7' ) :  450,
              ( 'Location 1', 'Location 8' ) :  575,  ( 'Location 1', 'Location 9' ) :  400,  ( 'Location 1', Location10   ) :  525
.
.
.goes down like this.
But when ı run the model ı got this warning:
Constraint programming constraints cannot be used in combination with real valued variables, only with integer valued variables, element valued variables, and activities.  The real valued objective variable is an exception.  The mathematical program "Min_Problem_Weight" has both constraint programming constraints and real valued variables, for instance constraint "Distance_F2_F3" and variable "Fac_Weight".

"Fac_Weight" is my final variable which is optimized by mathematical model.

So can you help me? How can I gather 2 facilities which must be adjacent? Or do you have any idea for this constraint?

Thank you in advance...

Bahadır ECE

Marcel Hunting

unread,
Dec 24, 2014, 3:58:17 AM12/24/14
to ai...@googlegroups.com
Hi,

Your constraint Distance_F2_F3 is written as a logic constraint which is only supported by constraint programming in AIMMS. It seems to me that your constraint should enforce Assignment('facility 2',j) or Assignment('facility 3',l) to be 0 if Distance_Locs(j,l) is not between 125 and 200. You can also formulate that as:

   Constraint Distance_F2_F3 {
        IndexDomain: (j,l) | (Distance_Locs(j,l) < 125) or (Distance_Locs(j,l) > 200);
        Definition: {
            Assignment('facility 2',j) + Assignment('facility 3',l) <= 1;
        }

Best regards,

Marcel Hunting
AIMMS Optimization Specialist

Bahadır ECE

unread,
Dec 24, 2014, 6:39:16 AM12/24/14
to ai...@googlegroups.com
Hello Mr.Hunting,
Thank you so much for your reply :)

Your advice fit perfectly.

But I have 4 facilities which should be located together with no any other facility included in the group.
(the allocations can be any "L" type any "I" type or any "T" type or any square type:
x   or   x  or       x  or     xx  or   xxx or  xxx or xxxx or xxx
x         x            x         xx           x      x                      x
x         xx        xx
x
                   
How should I introduce these allocations to the model? I have all the rectilinear distances between locations as parameter and Assignment variables (sent with the previous mail). I have tried to limit the distances between them (max 525m) but it locates other facilities into the group also. (The dimensions of a location is 125*200 . I have 20 similar locations next to each other in a rectangular area with 500*1000 dimensions which constitutes a 4x5 locations). Should I again write constraints with distances?

Thank you in advance.
 

Bahadır ECE

--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted

bece...@gmail.com

unread,
Jan 3, 2015, 8:05:01 PM1/3/15
to
Hello all,
I have 4 facilities(out of 20 facilities) which should be located together with no any other facility included in the group.
(the allocations can be any "L" type any "I" type or any "T" type or any square type.
How should I introduce these allocations to the model? I have all the rectilinear distances between locations as parameter and Assignment variables (sent with the previous mails). I have tried to limit the distances between them (max 525m) but it locates other facilities into the group also. (The dimensions of a location is 125*200 . I have 20 similar locations next to each other in a rectangular area with 500*1000 dimensions which constitutes a 4x5 locations). Should I write constraints with distances?
Please help.

Marcel Hunting

unread,
Jan 7, 2015, 11:33:57 AM1/7/15
to ai...@googlegroups.com
Hi,

I do not understand what you mean by this: "I have 4 facilities(out of 20 facilities) which should be located together with no any other facility included in the group.". Does it mean that if one of the 4 facilities is selected then also the other 3 should be selected, and none of the 16 facilities outside this group of 4?

Best regards,

Marcel

Bahadır ECE

unread,
Jan 7, 2015, 12:14:56 PM1/7/15
to ai...@googlegroups.com
Hello Mr.Hunting

I mean first 4 facilities (from 20 facilities) should be adjacent to each other. This adjacency situation is not important. (Ex.Facility 1 can be adjacent to 2 or 3 or 4 or 2,3 or 2,4 or 3,4 or 2,3,4. ) But at least from 1 side they should be adjacent. And being adjacent means the distance between them is either 125(horizontally) or 200(vertically). So these 4 facilities can constitute a shape of I or T or L or a square (locations are rectangular) .

(I have introduced a binary variable with the name "adj" and attended f and f1 as indexes from the subset of facilities 1-2-3 and 4.And added some constraints."i" are facilities and "j,l" are locations to assign.I have not written all sets, but the important part is below.)

So far I have introduced these:


 Variable Assignment {
        IndexDomain: (i,j);
        Range: binary;
    }
    Constraint Loc_Constraint {
        IndexDomain: i;
        Definition: sum(j, Assignment(i,j))=1;
    }
    Constraint Fac_Constraint {
        IndexDomain: j;
        Definition: sum(i, Assignment(i,j))=1;
Set Fac_1234 {
        SubsetOf: Facilities;
        Index: f, f1;
        Definition: data { 'Facility 1', 'Facility 2', 'Facility 3', 'Facility 4' };
Variable Adj {
        IndexDomain: (f,f1);
        Range: binary;
    }
    Constraint adj_3 {
        IndexDomain: (f,f1);
        Definition: Adj(f,f1)=Adj(f1,f);
    }
    Constraint adj_4 {
        Definition: Adj('facility 1','facility 1')=0;
    }
    Constraint adj_5 {
        Definition: Adj('facility 2','facility 2')=0;
    }
    Constraint adj_6 {
        Definition: Adj('facility 3','facility 3')=0;
    }
    Constraint adj_7 {
        Definition: Adj('facility 4','facility 4')=0;
    }
    Constraint adj_8 {
        Definition: Adj('facility 1','facility 2')+Adj('facility 1','facility 3')+Adj('facility 1','facility 4')>=1;
    }
    Constraint adj_9 {
        Definition: Adj('facility 2','facility 1')+Adj('facility 2','facility 3')+Adj('facility 2','facility 4')>=1;
    }
    Constraint adj_10 {
        Definition: Adj('facility 3','facility 1')+Adj('facility 3','facility 2')+Adj('facility 3','facility 4')>=1;
    }
    Constraint adj_11 {
        Definition: Adj('facility 4','facility 1')+Adj('facility 4','facility 2')+Adj('facility 4','facility 3')>=1;
    }
    Constraint adj_12 {
        IndexDomain: (j,f1);
        Definition: Assignment('facility 1',j) = Adj('facility 1',f1);
    }
    Constraint adj_13 {
        IndexDomain: (j,f1);
        Definition: Assignment('facility 2',j) = Adj('facility 2',f1);
    }
    Constraint adj_14 {
        IndexDomain: (j,f1);
        Definition: Assignment('facility 3',j) = Adj('facility 3',f1);
    }
    Constraint adj_15 {
        IndexDomain: (j,f1);
        Definition: Assignment('facility 4',j) = Adj('facility 4',f1);

Are they true? I am not sure if there is a short way of writing all of these. And now I have to say to AIMMS that

Adj(f,f1)=1 if Distance_Locs(j,l) is between 125 and 200. (I have a Distance_Locs parameter showing all distances between locations)
But when I write this
Constraint adj_16 {
        IndexDomain: (j,l) | Distance_Locs(j,l) > 124 or Distance_Locs(j,l) < 201;
        Definition: adj('facility 1','facility 2')=1;

I have an unused index of j and l.


I hope I could explain. If there is another way for adjacency which is more applicable please help.
Thank you very much...

Bahadır

Bahadır

--

Marcel Hunting

unread,
Jan 8, 2015, 6:18:15 AM1/8/15
to ai...@googlegroups.com
Hi,

Next time, please zip your AIMMS project and post it here. Now it is unclear to what set the indices i and j belong (I assumed they belong to the set Facilities).

You can combine the constraints adj_4, ..., adj_7 into one constraint:

    Constraint adj_4_7 {
        IndexDomain: (f);
        Definition: Adj(f,f)=0;
    }

In the same way you can combine the constraints adj_8, ..., adj_11 into one constraint:

    Constraint adj_8_11 {
        IndexDomain: f;
        Definition: sum( f1 | f1 <> f, Adj(f,f1) ) >= 1;
    }

The constraints adj_12, ..., adj_15 can also be combined in a similar way, but I leave that as an exercise.

The definition of constraint adj_16 indeed does not use j and l in its definition. It is unclear to me to which set(s) j and l belong, and what the relation is between Distance_Locs(j,l) and Adj(f,f1). Without knowing that I cannot help you.

Best regards,

Marcel

Bahadır

2015-01-07 18:33 GMT+02:00 Marcel Hunting:
Hi,

I do not understand what you mean by this: "I have 4 facilities(out of 20 facilities) which should be located together with no any other facility included in the group.". Does it mean that if one of the 4 facilities is selected then also the other 3 should be selected, and none of the 16 facilities outside this group of 4?

Best regards,

Marcel

On Sunday, January 4, 2015 2:05:01 AM UTC+1, Bahadır ECE wrote:
Hello all,
I have 4 facilities(out of 20 facilities) which should be located together with no any other facility included in the group.
(the allocations can be any "L" type any "I" type or any "T" type or any square type.
How should I introduce these allocations to the model? I have all the rectilinear distances between locations as parameter and Assignment variables (sent with the previous mails). I have tried to limit the distances between them (max 525m) but it locates other facilities into the group also. (The dimensions of a location is 125*200 . I have 20 similar locations next to each other in a rectangular area with 500*1000 dimensions which constitutes a 4x5 locations). Should I write constraints with distances?
Please help.

Thank you in advance.

Bahadır ECE

--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+unsubscribe@googlegroups.com.

Bahadır ECE

unread,
Jan 8, 2015, 9:43:13 AM1/8/15
to ai...@googlegroups.com
Hello Mr.Hunting

Thank you for your reply.
indexes "j" and "l" belong to the set "Locations" and "f" and "f1" are belong to the set of "Fac_1_2_3_4" which is a subset of "Facilities" (with all 20 facilities).
Adj(f,f1) is a binary variable for adjacency situation between first 4 facilities (set of Fac_1_2_3_4).
There is a parameter with the name "Distance_Locs" that shows distances between Locations ("Locations" set with the indexes j and l)
Every facility from set Facilities (20 facilities) are going to be assigned to a location at the set of Locations. But first 4 facilities have to be adjacent to each other. So I want to describe adjacency situation with the distances between these locations that first 4 facilities are going to be assigned. (reason for the "adj_16" constraint). And I want model to know if the distance between 2 locations is between 125 and 200 then this situation means adjacency and it is appropriate for first 4 facilities to be assigned(adj(f,f1)=1). Otherwise it should not be located.
I hope I could explain. I have also sent a zip file of the model  and (in case it cant be opened) a text file of my model.

Hope to hear from you

Bahadır



Bahadır

To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
Assignment.zip

Marcel Hunting

unread,
Jan 9, 2015, 6:07:31 AM1/9/15
to ai...@googlegroups.com
Hi,

I introduced a new parameter that indicates that two locations are adjacent:

    Parameter Locations_are_adjacent {
        IndexDomain: (j,l);
        Range: binary;
        Definition: {
            if ( Distance_Locs(j,l) > 124 or Distance_Locs(j,l) < 201 ) then
                1
            else
                0
            endif
        }
    }

Using this new parameter I defined constraint adj_16 as:

    Constraint adj_16 {
        IndexDomain: (f,j);
        Definition: Assignment(f,j) + sum( (f1,l) | f1 <> f and (not Locations_are_adjacent(j,l)), Assignment(f1,l) ) <= 1;
    }

This constraint means that if facility f is assigned to location j then none of the other facilities in Fac_1234 can be assigned to a non-adjacent location.

I hope this helps.

Best regards,

Marcel

On Thursday, January 8, 2015 at 3:43:13 PM UTC+1, Bahadır ECE wrote:
Hello Mr.Hunting

Thank you for your reply.
indexes "j" and "l" belong to the set "Locations" and "f" and "f1" are belong to the set of "Fac_1_2_3_4" which is a subset of "Facilities" (with all 20 facilities).
Adj(f,f1) is a binary variable for adjacency situation between first 4 facilities (set of Fac_1_2_3_4).
There is a parameter with the name "Distance_Locs" that shows distances between Locations ("Locations" set with the indexes j and l)
Every facility from set Facilities (20 facilities) are going to be assigned to a location at the set of Locations. But first 4 facilities have to be adjacent to each other. So I want to describe adjacency situation with the distances between these locations that first 4 facilities are going to be assigned. (reason for the "adj_16" constraint). And I want model to know if the distance between 2 locations is between 125 and 200 then this situation means adjacency and it is appropriate for first 4 facilities to be assigned(adj(f,f1)=1). Otherwise it should not be located.
I hope I could explain. I have also sent a zip file of the model  and (in case it cant be opened) a text file of my model.

Hope to hear from you

Bahadır



Bahadır

Bahadır ECE

unread,
Jan 9, 2015, 8:15:42 AM1/9/15
to ai...@googlegroups.com
Hello Mr.Hunting,

Thank you for your kind attention.

I have tried to introduce the parameter and the constraint.
But it gives warning again and I couldn't understand why.
Please have a look at that.

Thank you


Bahadır

To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
Assignment2.rar

Marcel Hunting

unread,
Jan 9, 2015, 11:10:13 AM1/9/15
to ai...@googlegroups.com
Hi,

The problem is infeasible as there are no four locations that are pair-wise adjacent.

Best regards,

Marcel

On Friday, January 9, 2015 at 2:15:42 PM UTC+1, Bahadır ECE wrote:
Hello Mr.Hunting,

Thank you for your kind attention.

I have tried to introduce the parameter and the constraint.
But it gives warning again and I couldn't understand why.
Please have a look at that.

Thank you


Bahadır

Bahadır ECE

unread,
Jan 21, 2015, 1:34:07 PM1/21/15
to ai...@googlegroups.com
Hello Mr.Hunting,

I made the problem simple since AIMMS trial licence has expired.( but the variables seem much more than 300).

I have 10 facilities to be located 10 locations. Facilities 1,2,3,4 and 5,6,7,8 should be adjacent to each other in many ways/shapes (Each one should be adjacent to at least one in its own group(ex. Facility 1 can be adj to 2 or 3 or 4 or 2,3 or 3,4 ....etc)). Facilities 2,3 and 6,7 should be adjacent to each other. I have written the constraints and defined Assignment and Adjacency variables.

I have applied for a license, but I want to know if the model is working and if my constraint definitions are correct because I get a warning regarding variable amount.
I would be glad if you can check. You can find the model attached.

Thank you in advance...

Assignment-01.21.rar

Bahadır ECE

unread,
Jan 22, 2015, 2:57:27 AM1/22/15
to ai...@googlegroups.com
Hi,

Please ignore the model in my previous mail.(mail content is valid) Here is the modified model, but why do I get a "solution does not exist error"?
I want to product 2 variables. When it gave error I made the production with constraints which is written in user guide as a linear program trick. But still I have an error.

Regards...

21 Ocak 2015 Çarşamba 20:34:07 UTC+2 tarihinde Bahadır ECE yazdı:
Assignment-01.21.rar

Bahadır ECE

unread,
Jan 27, 2015, 4:29:22 AM1/27/15
to ai...@googlegroups.com
Hi,
How can I make one facility(for ex. 'facility 1') to be adjacent to at least one of the facilities in Facility_1234 set which consists 4 facilities from 1 to 4? I tried to introduce a binary adjacency variable and want to make constraint like 

index: (j,l) | not Loc_are_adj(j,l)
Adjacency('Facility 1','Facility 2') < Assignment('Facility 1',j) * Assignment('Facility 2',l)

but it does not work while one or either of the Assignment binaries is 0. What can you suggest?
(Loc_are_adj(j,l) is a parameter that means locations which are adjacent to each other and facilities in Facility_1234 set wanted to be assigned to locations that can be adjacent to other facilities in the same set.)

Regards
Bahadır

Bahadır

--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.

Bahadır ECE

unread,
Jan 27, 2015, 5:09:12 AM1/27/15
to ai...@googlegroups.com
Hello,
I also tried this:

index: (j,l) |  Loc_are_adj(j,l)
Adjacency(f,f1) = Assignment(f,j)*Assignment(f1,l)

(f and f1 are indexes for facilities1 to 4.)

but product of 2 variables are not allowed in MIP so I introduced these as

Adjacency(f,f1)>=Assignment(f,j)
Adjacency(f,f1)>=Assignment(f1,l)
Adjacency(f,f1)<=Assignment(f,j)+Assignment(f1,l) - 1

but still get warnings,

PLEASE HELP

thanks in advance...
Bahadır

Bahadır

Bahadır ECE

unread,
Jan 27, 2015, 7:03:15 AM1/27/15
to ai...@googlegroups.com
And also this:

Variable
Adjacency (f,f1)
Range: integer

Constraints:
C_1: index domain: (j,l) | Distance(j,l)<201 and Distance(j,l)>124
Assignment('Facility 1',j)+Assignment('Facility 2',l)=Adjacency('Facility 1','Facility 2')
C_2:
Assignment('Facility 1',j)+Assignment('Facility 3',l)=Adjacency('Facility 1','Facility 3')
C_3:
Assignment('Facility 1',j)+Assignment('Facility 4',l)=Adjacency('Facility 1','Facility 4')
C_4:
Adjacency('Facility 1','Facility 2')+Adjacency('Facility 1','Facility 3')+Adjacency('Facility 1','Facility 4') >= 2

still "solution does not exist"


waiting for help...
thank you
Bahadır

Bahadır

Bahadır ECE

unread,
Feb 2, 2015, 6:30:03 AM2/2/15
to ai...@googlegroups.com
Hello All,

I've done the adjacency constraints and run perfectly.
When I run the model in a small type project (only about constraints) I've no any warning and have the results.
But at the file attached which is a big one considering other variables and parameters that the model has to solve and determine, I have a warning.
Do you have any idea where this problem may arise?
Thank you...
Bahadır


Deneme7-01.31-son.rar

Bahadır ECE

unread,
Feb 2, 2015, 7:01:18 AM2/2/15
to ai...@googlegroups.com
Hi,

I've found the mistake. Sorry for inconvenience.

2 Şubat 2015 Pazartesi 13:30:03 UTC+2 tarihinde Bahadır ECE yazdı:
Reply all
Reply to author
Forward
0 new messages