Visit given city before a given cumulative distance in the traveling salesman problem

I would like to add an additional constraint to the traveling salesman problem: that a given city is visited within a given distance (say 100) from start. Is there a way to do this? My question is related to this unanswered CS question.

I have a mixed integer program using the R package CVXR that find the shortest route without subroutes (see below). The city order is represent in the vector node_order. The strategy I’ve pursued so far is:

  1. Re-organize node_order so that the index is the order and the value is the city id
  2. Look up the associated distances in distances
  3. Compute a vector with the cumulative sum of these distances.
  4. Add the constraint that city i must occur before the first index in (3) exceeding the distance constraint for that city.

The issues I’ve encountered with this approach is that I have not found a way to include finding-index-by-value into the optimization in CVXR. This is needed in both step (1) and (4) above. Maybe this is possible after all, or there is another approach? I am willing to use other packages than CVXR and other software than R.

My current program:

library(CVXR)  # Make distances N = 10 distances = matrix(1:(N*N), ncol = N)  # Flag 1 iff we travel that path. 0 otherwise do_transition = Variable(N, N, boolean = TRUE)  # Minimize the total duration of the traveled paths. objective = Minimize(sum(do_transition * distances))  # Only go one tour. Order is 1:(N-1) node_order = Variable(N-1, integer = TRUE) ii = t(node_order %*% matrix(1, ncol = N - 1))  # repeat as N rows jj = node_order %*% matrix(1, ncol = N - 1)  # repeat as N cols   # Constraints constraints = list(   do_transition * diag(N) == 0,  # Disallow transitions to self (diagonal elements)   sum_entries(do_transition, 1) == rep(1, N),  # Exactly one entrance to each node   sum_entries(do_transition, 2) == rep(1, N),  # Exactly one exit from each node   (jj - ii) + N * do_transition[2:N, 2:N] <= N - 1,  # One tour constraint (no subtours)   node_order >= 1,   # This interval represents order as ranks (1 to N-1)   node_order <= N-1 )  # Find optimum solution = solve(Problem(objective, constraints)) 

A bit of code pertaining to my current (unsuccessful) attempts:

# Get tour order #tour = order(c(NA, result$  getValue(node_order)))  # R solution tour = rep(NA, N-1) tour[result$  getValue(node_order)] = 2:N  # Get tour distances distances_optim = diag(distances[tour, tour[2:N]])  # Tour cumulative distances distances_cumul = cumsum_axis(distances_optim) 

Encounter rules while traveling in a caravan in Jade Regent campain

In the Jade campain book the caravan encounter rates are defined by chapter with the following kind of statements :

As the caravan travels north, there’s a 10% chance of an encounter each day. Encounters indicated with an asterisk have a 50% chance of occurring at night while the caravan is camped. All other encounters occur while the caravan is on the move. Encounters don’t occur if the caravan camps at a settlement. If an encounter occurs, roll on the following table to see what the PCs have encountered. Note that all of the following encounters are caravan encounters and use the caravan combat rules found online in the free Jade Regent Player’s Guide

What is not in bold is pretty straightforward, however I am struggling with the bold parts. If I read that straight, these rules would mean that each day I would roll for a 10% chance of an encounter (then pick the encounter from the encounter table of course). Then there would be, granted the party does not make camp near a city, an independent 50% chance that one encounter with an * would occur, that would mean that if multiple encounters were having an * symbol they all could occur at a single night!

I searched on the internet of course, but could not find this question asked. However I am more confused by a forum (did not save the source…) that stated that each day the 10% chance was cumulative (day 1 : 10%, day 2: 20%, etc) and was reset to 10% each time an encounter occured.

On the first chapter of the adventure I DM using my understanding of the rules, and it gave pretty lame results. Only one event occured during a ~14 days trip, resulting only in a bad weather. Also the night rule seemed pretty harsh regarding the fact that there were not so many settlements on the road.

According to you, how should I interpret those rules ? Please be aware that my native language is French and I could have missed important nuances in the text (also french rules are not helping to solve my question…).

Can you cast a spell as a ritual while traveling?

As stated in the Players’s Handbook (p. 202),

When you cast a spell with a casting time longer than a single action or reaction, you must spend your action each turn casting the spell, and you must maintain your concentration while you do so […]

Aside of that, no other limitation seems to apply to ritual casting (if your class grants you the ability to do so).

Is it safe, then, to assume that one could travel and cast a spell as a ritual at the same time?

The question came up at the table, as most of us had that (mis)conception of rituals being cast while tracing cabalistic signs on the ground, pouring dusts or other components over it and such…

Traveling through the Astral Plane

I’m new to D&D and I don’t understand all of its concepts, for example, Astral Plane. From what I understand, you can travel there physically through a portal and travel to other planes this way, but when you use certain spells, your consciousness is transferred to the Astral Plane and is connected to Your body with a silver cord. The body stays where it was and someone must take care of it and when the cord is broken, You die. What does happen when in such form one enters a portal to another plane?

Grouping n points into groups of size m with objective to have least traveling distance in each group


  • There are “n” jobs which are distributed over the city.
  • Company has “k” available workers.
  • Each worker can do “x” jobs per day.
  • “x” is dependent to the worker skills and the distance he travels each day so it’s not a constant.
  • Workers have no initial traveling distance.
  • “s” is a set that shows each workers can do how many jobs based on the distance he travels
  • “d” is the number of days that takes for company to do all the jobs.

Objective: Minimize the “d”

I know this problem is probably NP-hard so I don’t need the exact answer. I think it’s kinda a variation of Traveling salesman problem combining with scheduling and assignment problems.

My algorithm for this problem is to “some how” efficiently ( of course not the most efficient way ) grouping the jobs based on their traveling distance in the groups in to groups of “m” which is the mean of set “s”. Then after each day rerun the algorithm to get better results.

My question is what is the best way to do that grouping? Anyway if you know a better algorithm I would be more than happy to know them.

How do I get a planar traveling party to use survival/spells slots for food/drink instead of an artificer’s replicate magic item feature?

Any solution is welcome. Including just letting the artificer spend his infusion.

Background: I have a planar traveling campaign that sometimes runs into survival issues.

With Eberron coming out I have promised my players can use Artificers. The problem is a level 2 Artificers can make an alchemy jug that would largely invalidate the spell “goodberry”, the spell “create food and drink”, and the player with high survival.

They already have an alchemy jug. But magic items can disappear. I don’t know how to consistently remove a magic item that players can make themselves every day. From what I have read it will not require an item to create, and the player can infinitely replace it.

Do encumbered players suffer any penalties when exploring and/or traveling?

The current 5e campaign I’m running uses the encumbrance variance rules and demands a lot of travel and resource management on the part of the players.

This brought up questions about penalties when traveling while encumbered/heavily encumbered (especially from players with lower strength scores)…

It is stated in the PHB that being encumbered reduces a player’s movement in combat while being heavily encumbered drops movement further, and negatively affects attack rolls, ability checks, as well as certain saving rolls. That is clear enough! The DMG adds:

The difference between walking speeds can be significant during combat, but during an overland journey, the difference vanishes as travelers pause to catch their breath, the faster ones wait for the slower ones, and one traveler’s quickness is matched by another traveler’s endurance.

So, it appears, according to RAW, that even a heavily encumbered party’s travel speed is not affected when exploring or traveling, nor do they suffer any other penalties associated with travel (e.g. reduced distance covered/marching time, increased risk of exhaustion, etc.). We aren’t missing anything obvious?

What is the difference between nearest and cheapest insertion algorithms for a Traveling salesman problem?

I know that in the cheapest insertion algorithm we include the node which is not in the “base group” that has smaller cost given all possible combinations, and for the nearest we include the node with smaller cost. So, do they differ only in how combinations are made?

For example, I have the following weighted matrix graph:

     2  13  14  17  20 2  0.0 Inf Inf 1.9 1.7 13 Inf 0.0 7.3 7.4 7.2 14 Inf 7.3 0.0 7.7 7.8 17 1.9 7.4 7.7 0.0 9.2 20 1.7 7.2 7.8 9.2 0.0 

If I start from node 2 from each method:


1) 2-20-2

2.1) 2-17-20-2 = 12,8

2.2) 2-17-20-2 = 12,8 *Choosen

3.1) 2-13-20-17-2 = Inf

3.2) 2-20-13-17-2 = 18,2 *Choosen

3.3) 2-20-17-13-2 = Inf

4.1) 2-14-20-13-17-2 = Inf

4.2) 2-20-14-13-17-2 = 26,1

4.3) 2-20-13-14-17-2 = 25,8 *Choosen one

4.4) 2-20-13-17-14-2 = Inf


1) 2-20-2 2.1.a) 2-13-20-2 = Inf

2.1.b) 2-20-13-2 = Inf

2.2.a) 2-14-20-2 = Inf

2.2.b) 2-20-14-2 = Inf

2.3.a) 2-17-20-2 = 12,8

2.3.b) 2-20-17-2 = 12,8

So, with the cheapest approach, do I explicitly make all combinations?

For what applications of the traveling salesman problem, does visiting each city at most once truely matter?

Traditionally, the traveling salesman problem has you visit a city at least once and at most once.

However, if you were an actual traveling salesman, you would want the least cost route to visit each city at least once, and you wouldn’t be bothered visiting a city 2, 3, or more times. For given city, you might stop and hawk your wares only once, and on subsequent visits, only drive through the city without stopping.

Consider an undirected graph having a city incident to exactly two edges. The cost on one of these edges is only 10 units, while the cost on the other is 99,999,999,999. If you insist on visiting each city at most once, then you are forced to incur the cost of the high cost edge. However, if you allow yourself to visit cities multiple times, then you simply leave the way you came in (on the low cost edge). The low cost edge leads you back to a city you’ve passed through before.

The traveling salesman problem is highly contrived for an actual traveling salesman. I want to give students an application for which there’s a real incentive to visit each city at most once. For what applications is visiting each city a critical aspect of the problem?

Can you ritual cast multiple Phantom Steeds and continue re-summoning them while traveling?

Can you ritual cast the Phantom Steed spell multiple times and in practice just re-summon them while you are traveling? So for example, could a Wizard ritual summon a horse, three times in a row. And then just focus on re-summoning them while he’s riding one of them. The spell lasts 1 hour, ritual casting it 3 times would take 33 minutes. So he should have more than enough time to summon new horses for himself and his party before any of the individual horses disappear. Is this correct?