# How do I write the following constraint?

I have defined the index for time to be T = [1,2,3,4,5,6]. I want that that the demand that to be addressed twice in a given a time period, when the difference between the time the demand is addressed the first time and the demand is addressed the second time is 2. Suppose the demand at a location is is given by $$D_i$$, where $$i \in I$$ represents the location of the demand and $$\omega_{ijt}$$ are the number of people who are meant to be located from location $$j$$ to location $$i$$ in a time period $$t\in T$$. Currently I have that $$\sum_{j \in J} \sum_{t \in T} \omega_{ijt} = D_i$$, which will ensure that the demand is allocated to location $$j$$ in time t. However, how can introduce the idea of having the same demand reintroduced in my model, when the difference between the demand first addressed and the the model time is $$2$$.

Edit: If I have a demand of 40 people at a, 50 people at b, 60 people at c. I want that all of these people at locations $$a,b,c \in I$$ visit location $$j \in J$$ within a certain time period $$t < T$$, where T can be $$6$$ weeks and $$t$$ can be 3 weeks . This means that all of the demand can be addressed within 3 weeks. Next, I want that this demand may only visit the facility again if difference between the time that the demand first visited and next visit will be 3 weeks. I do not know how to model this.

Thanks.

• It's not clear what you mean Aug 5, 2021 at 12:06
• @Optimization team, in a certain span of say t = 6, I want my demand to be covered. Additionally, I want that if t - t(when demand was addressed) =2, then demand should be readdressed.
– user4387
Aug 5, 2021 at 12:57
• You say in reference to your one equation that it "will ensure that the demand is allocated to location $j$ in time $t$." The right side, however has demand for location $i$, and that demand is not being addressed at a particular time $t$ (since $t$ is an index of summation). Please try to rewrite your question in a clearer manner.
– prubin
Aug 5, 2021 at 16:08
• @prubin, demand is not age dependent..
– user4387
Aug 5, 2021 at 16:37
• I think a small numerical example would help clarify the desired behavior. Aug 7, 2021 at 18:23

When you reason about sums of people moving from $$a$$ to $$b$$ and sums of people being at $$a$$ at time point $$t$$ you can't reason at a level of the individual. In your formulation you can't express constraints on the position in time of the individual as you currently don't describe the position where an individual is in your model.

To track the position of individuals you need to introduce a boolean array of $$\text{is_at}_{p, l, t}$$ where $$p$$ is the unique number of the person and $$l$$ is it's location at time point $$t$$.

Since you probably don't want one person to be at multiple locations at the same time you need introduce some constraint like $$\forall p \in \text{Persons}, \forall t \in \text{Time}: \sum_{l \in L} \text{is_at}_{p, l, t} \leq 1$$ meaning one person can be at most at one location at a time.

On this state it is possible to express that a certain individual needs to revisit the same place 2 time steps later:

$$(\text{is_at}_{p, l, t} \land \neg \text{is_at}_{p, l, t-2}) \implies (\text{is_at}_{p, l, t+2})$$

which reads as if Individual $$p$$ visited $$l$$ at time point $$t$$ but not at $$t-2$$ then $$p$$ needs to visit $$l$$ at $$t+2$$. You might have noticed that this is not in a MILP form but it can be converted into one using these equivalences. Note that around the boundaries of your time interval you can simplify this formulation as $$t+2$$ or $$t-2$$ might not exist and you need to define what that means for your model. This formulation will also be a lot bigger then your current one as you are keeping track of individuals and not just sums of people.

You can also modify this formulation to allow individuals to visit after 2 or 3 or 4 days if he never visited this place before: $$(\text{is_at}_{p, l, t} \land \neg ( \bigvee\limits_{i=1}^{t-1} \text{is_at}_{p, l, i})) \implies (\text{is_at}_{p, l, t+2} \lor \text{is_at}_{p, l, t+3} \lor \text{is_at}_{p, l, t+4})$$ Or do another large number of simple modifications that might be able to capture what you want.

• No this is not the correct formulation. I just need a simple constraint a modified version of the one I wrote. Additionally, we can have people at my facilities from different locations.
– user4387
Aug 7, 2021 at 21:43
• According to my understanding of your problem and math there is no such modification. If you want to trace individuals around you can't do so without knowing where persons are. If you want to do something else then please make your question a lot clearer as nobody else seems to get it either. Aug 7, 2021 at 21:47
• my question is really clear honestly. We dont have a unique ID for a person. This may help: If a person from location i visits location j, then he/she must do so after 2 time periods too.
– user4387
Aug 8, 2021 at 6:26
• can you help me write the MILP formulation?
– user4387
Aug 8, 2021 at 10:32
• You can't track individuals without assigning them a separate variables (is_at) and the index into is_at is the ID. Your description is not clear. It might help if you write it in your native language and add that so we can have Google translate your message. @Jimjamlorde Aug 8, 2021 at 11:09