\documentclass[]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage [] {hyperref}
\usepackage{graphicx}
\usepackage{refcount}
\usepackage{fontawesome5}

%opening
\title{Simutrans-extended\linebreak
	From A to B.\linebreak
	Simple transformation of goods\linebreak Elemental algebraic approach.\footnote{Licensed under the terms of the GPL v3.}}
\author{jimishol}
\begin{document}
	\maketitle
\begin{abstract}
	It will be examined a simple transformation of goods from production point to its consumer  destination. The time i spent in this study, I feel it belongs to game play time, even if i did not started my new game yet. It might belong to game play time of some readers that intent to start a new map too, before they begin their real play.
\end{abstract}
\section{Convoy's relative system of reference.}
In normal system of reference we use length measured in kilometers and time measured in hours.
\paragraph{A relative, to a convoy, system of reference} is defined by units of length and time measured both in months and depends on the velocity of that convoy, as $km/h$ in normal system of reference.
\subsection{Units}
\subsubsection{Time unit}
We measure time in months. 
A month is defined as
\[1 \ month = m \ hours.\] In default settings $m = 6.4$. 
\paragraph{Conversion of time} is done by
\begin{equation}\label{convert_time}
	T(t) = t/m
\end{equation}
\subsubsection{Length unit}
Relatively to the velocity \textit{v\ km/h} of a convoy, we measure the distances it travels by the time it needs to cover them.
\paragraph{A length of 1 month,} relatively to a convoy that travels at velocity \textit{v km/h}, is the distance it travels in \textit{1 month}.
\paragraph{Conversion of length} is done by

\begin{equation}\label{convert_length}
	L(l, v) = \frac{l}{v * m}
\end{equation}
So, \textit{1 km} equals to $L(1, v)
\ months.$  Additionally,\\a definite distance $l\ km$, that is constant in normal system of reference, varies in relative system, depending each time on the convoy's velocity in the normal system of reference.
\subsection{Velocity}
Velocity is defined as the traveled distance per unit of time. 
\[V=\frac{\Delta L}{\Delta T}\]
In some cases, velocity is defined relatively to some node of transportation's network. When the velocity is considered as towards some node, it is defined negative. When the velocity is considered as away from some node it is defined positive.\\
If velocity is constant in time, we get
\[V=\frac{L}{T}\]
Dividing length month units per time month units, has as result dimensionless units for velocity.
If another vehicle with speed \textit{v'} covers a distance \textit{L'} in time \textit{T'} then
$V = L'/T'= \frac{l'}{v*t'}=v'/v.$ So, the velocity of others is the ratio of their speed against ours. 

\textbf{The convoy's velocity} that varies in normal system, is constant and \textbf{equals to 1}, in convoy's relative system of reference.\label{velocity_one}

\section{Transportation of goods}
During transportation, goods are moving from one location to another. Unless otherwise stated, we will consider that the velocity of goods, by which a transportation is created, is constant in normal system of reference.
\subsection{Properties of transportation}
Because transportation of goods is a discontinuous process, we define properties of transportation by the their average values over time.
\paragraph{Flow of goods} at a location is defined as the quantity of goods that pass through that location per unit of time. If $Q$ goods pass through in $T$ time, then their flow $F$ is given by
\begin{equation}\label{Flow}
	F=\frac{Q}{T}\ goods/month
\end{equation}
In case that the flow is considered as towards the location, it is defined negative. In case that the flow is considered as away from the location it is defined positive.

\paragraph{Momentum of goods,} is defined as the product of their quantity multiplied by their velocity during movement. Assuming a movement of $Q$ goods in constant velocity $V$, their momentum $M$ is given by
\begin{equation}\label{Momentum}
	M=Q*V \ goods
\end{equation}
Because velocity $V$ is dimensionless, momentum of goods is measured just in \textit{goods}. If we solve formula \eqref{Flow} for $Q$ and substitute to \eqref{Momentum} we get
\begin{equation}\label{momentum-flow}
	M=F*T*V=F*L
\end{equation}
We see that the momentum of a transportation of goods equals to the product of their flow multiplied by the distance they travel.

\paragraph{Work of a transfer} of goods $W$, is defined as the product of their quantity $Q$ multiplied by the distance $L$ they traveled.
\begin{equation}\label{Work}
	W=Q*L\ goods*months
\end{equation}

\paragraph{Power that creates a transfer} $P$ is defined as the work of a transfer created per unit of time.
\begin{equation}\label{Power}
	P=\frac{W}{T}\ goods
\end{equation}
By substituting $W$ from \eqref{Work} we get
\[P=\frac{W}{T}=Q*\frac{L}{T}=Q*V=M\]
and the conclusion that the power that creates transfer's work equals to the momentum of that transfer.

\subsection{Variations in stocks of goods}
Every location on a route of transportation can be consider as a potential stock, whose stored goods varies due to the flow of transportation.

Applying signed flows, in a location between nodes of a network of transportation, the sum of the negative flow, towards the location, and the equal but positive flow, away from it, equals to zero. There is no average variation of the quantity of goods at locations between the nodes. Considering the two nodes at the ends of a single line, the same flow that appears positive to the source node, appears negative to the destination node.

In every node of the network the sum $\varSigma F$ of all flows, that start or end to the node, equals to the average variation of goods per unit of time caused by the flows.

A source at a node of transportation's network produces goods per unit of time, where the variation $\Delta Q$ has a negative sign.

A sink at a node of transportation's network consumes goods per unit of time, where the variation $\Delta Q$ has a positive sign.

\paragraph{The average variation of goods,} in some node, per unit of time is given by the sum \[\frac{\Delta Q}{\Delta T} + \varSigma F\]
When the average variation of goods in a node is zero, we can say that the \textit{conservation law} is applied in that node and that, is expressed by the formula 
\begin{equation}\label{conservation}
\frac{\Delta Q}{\Delta T} + \varSigma F = 0	
\end{equation}

\section{Convoys}

In previous sections, we defined properties of transportation, based on thoughts of how they are created in real life. In this section we will turn our attention to how game convoys create transportation of goods.
\paragraph{All convoys runs scheduled loop routes.} They do not disappear after their delivery but return back to their origin, load again and repeat the process of transportation by running a next loop of it. We will calculate the properties of  transportation they create as average values referred on that one loop.
\subsection{The loop}
We restrict our attention to the simplest loop. A convoy departures from his origin A loaded by $q$, less than its capacity, goods, travels to his destination B with maximum available speed, unloads, returns empty back to origin A, again with maximum available speed, and loads to repeat the loop. If departures are scheduled it has to wait more till the next departure time comes.
\paragraph{Velocity} of a convoy always equals to 1 (see section \ref{velocity_one}). Recall that we use the relative to convoy system of reference and that means we need a velocity in normal system to defense to. Because a convoy have different velocity in each of the phases of loop, the referenced velocity will be the average velocity from all phases.
\paragraph{Duration} $T$ of each loop is the sum of \begin{itemize}
	\item time $T_d$ needed to travel from origin A to destination B
	\item time $T_u$ needed to unload his cargo of $q$ goods
	\item time $T_e$ needed to return empty to the origin A.
	\item time $T_l$ needed to load $q$ goods.
	\item time $T_w$ needed to wait for possible scheduled departures.
\end{itemize}
\begin{equation}\label{loop-duration}
	T = T_d+T_u+T_e+T_l+T_w\ months
\end{equation}
\paragraph{The distance of industries} we see in information popup window is euclidean. Profits most probably are based in this. Maintenance cost per distant are payed based on the greater actual route that convoys take to reach their destination. Profits come in slower pace too because convoys are delayed in reaching their destination. $dstCoeff$ is used to estimate the length of longer route.  If Manhattan distance is used then the coefficient is a number between $1$ and $\sqrt{2}$, depending on how diagonal is the straight euclidian route, where $1$ is for perfectly horizontal or perpendicular on map route.\\
Furthermore, traveled distance can be more if terrain forced us to use peculiar waypoints. In this case, line length in information gives the actual loop length as sum of euclidean distances and $dstCoeff$ should be $\frac{line\ length}{2* industries\ distance}$ times greater. I usually set it just as $dstCoeff=sqrt{2}$ and forget about it.
\paragraph{Length} of the loop, due to the fact that the velocity is always $V=1$, is expressed with the help of its duration. The length of the loop is expressed as $2*L$, where $L$ corresponds to the time would be needed to cross the distance between the source and the target of the transportation by a convoy that moves with average speed. Using the same meaning of indexes, we calculate the referenced average speed in normal system as \[\bar{v}=\frac{2*l}{dstCoeff*t_d+t_u+dstCoeff*t_e+t_l+t_w}\]
So, the length of the loop, referenced to the above average velocity,  is
\begin{equation}\label{loop-length}
	2*L=2*L(l,\bar{v})=T_d+T_e+T_u+T_l+T_w=T\ months
\end{equation}
The conversion from $t$ to $T$ is done by formula \eqref{convert_time}.\\
 We see that $L$ corresponds to the time needed by the convoy to cover the distance between his origin and  destination.

The length of loop has no upper limit as, theoretically, we can wait as long as we like by the use of scheduling. However, it has a minimum value that corresponds to convoy's maximum velocity and can be calculated with the help of \eqref{convert_length}.
\subsection{Convoy's power} to transfer goods is evaluated by the work produced during a loop divided by the duration of the loop.
\paragraph{Convoy's work,} during a loop, equals to the sum of work done during each phase of the loop. Lets look at it in normal system. If convoy carries $q$ goods, the work during loop equals to \[w=q*l_d=q*l\ goods*km\]
It is so because during all other phases either the convoy do not move or the its load is zero.

Converting to relative system we get
\begin{equation}\label{convoys-work}
	W=q*L\ goods*months
\end{equation}
\paragraph{Convoy's power} that produce the work equals to
\begin{equation}\label{convoys-power}
	P=\dfrac{W}{T}\stackrel{\eqref{loop-length},\ \eqref{convoys-work}}{=}\frac{q*L}{2*L}=\frac{q}{2}\ goods
\end{equation}

\subparagraph*{The power of a convoy to create transportation equals to the half of his loaded cargo.}\label{half-capacity}
From our calculations just after \eqref{Power} we see that the momentum of any transferred goods equals to the power that creates the transfer. So, we can also claim that
\subparagraph*{The momentum of goods transferred by the convoy equals to the half of his loaded cargo.}

\[P=M=\frac{q}{2}\]

\paragraph{Convoy's goal} is to transfer a determined variation of goods that are created due to production or consumption rates at some nodes of the network. We can foresee that it has to satisfy the need for exactly that variation to be transferred. If they create a transfer with more than the needed momentum, they will cost more. If they create a transfer with less than the needed momentum will not be paid as much as they could. This means that conservative of goods law \eqref{conservation} should be applied. In our simple case, the production or consumption rate is served by a single line of transportation and there is no need for the use of signed flows that concern mostly multiple flows around some node. In that case \eqref{conservation} gives
\[	\frac{\Delta Q}{\Delta T}=F \stackrel{\eqref{momentum-flow}}{\Rightarrow} M= \frac{\Delta Q}{\Delta T}*L\Rightarrow \frac{q}{2}= \frac{\Delta Q}{\Delta T}*L\Rightarrow\]

\begin{equation}\label{convoy-q}
	q= 2*\frac{\Delta Q}{\Delta T}*L
\end{equation}

As we mentioned we can increase the convoy's  demanded load $q$ by increasing, through scheduling, the needed time $L$ to reach its destination but no more than its capacity. We can decrease convoy's demanded load $q$ by decreasing the needed time $L$ to reach its destination, reducing his waiting times or through the choice of a faster convoy, but no more than its maximum velocity will allow.
\subparagraph*{Example 1} When it is best to create a ship, with maximum velocity $15km/h$ and capacity of 50 crates, that has to join docks $96km$ away from eachother? The ship will need about 1 month to reach its destination, $L=1\ month$. Its cargo is  $q=50\  crates$. When we have to satisfy a need of $\frac{\varDelta Q}{\varDelta T}=\frac{50}{2*1}=25$  crates per month.
\subparagraph*{Example 2} A convoy with maximum velocity $5km/h$ needs to transfer a production of 2 crates per month $8km$ away. The convoy will need about 1/4 of a month to reach its destination, $L=1/4\ month$. Its needed cargo is only $q=2*2*1/4=1\ crates$. Since no capacity is less than 1 crate, we can check many convoys with load or departure scheduling to see if any is profitable.


\section{Revenue}
\subsection{Distance cost per month}
Cost per distant is given as $cpd$ in cost per $km$. It is converted in new units by
\begin{equation}\label{cost_per_distance}
	Cpd = \frac{cpd}{L(1,\bar{v})}=\frac{cpd*l}{L(l,\bar{v})}\ \frac{distance\ cost}{month}
\end{equation}
We can see that as average speed is increasing, the $L(l,\bar{v})$ duration is decreasing and so, the cost per month is increasing because convoy covers more distance due to higher velocity.

\textit{It is convenient that this cost for distance, in cost per month units, can be added to maintenance cost per month.}

\subsection{Distance profit}

The transportation that a convoy creates, on long terms, is a continuous process. It is characterized by the flow, as goods transferred per unit of time, and the distance they travel. The payment is done per unit per distance. That means, the profit is actually money per month of convoy's operation and corresponds to the product of flow $F$ of goods multiplied by the distance $L$ they travel. So, from \eqref{momentum-flow}, convoys are payed for the momentum of the transportation they create. However, the maximum of reward will correspond to  momentum of the transportation that is asked for. Consequently, the maximum profit per month is achieved for the quantity of loaded goods that is given by the formula \eqref{convoy-q} and equals to \[Profit\ per\ month=Ppd*\frac{\Delta Q}{\Delta T}*L\]
where $Ppd$ is the profit per distance per unit in the relative system of reference. The conversion from $ppd$, that is referenced in goods list in game, is done by $Ppd=ppd/L(1,\bar{v})$. Substituting we get  

\begin{equation}\label{profit_per_distance}
	Profit\ per\ month = ppd*l*\frac{\Delta Q}{\Delta T}
\end{equation}
where $\frac{\Delta Q}{\Delta T}$ is the production or consumption rate or a ratio of them that convoy  is committed to serve.
\subsection{Revenue per month}
Since all variables in new units are converted in $month$ units and the maintenance cost per month do so, we are ready to combine all to calculate the revenue of $n$ convoys that do a simple transformation of goods. Our data are

\begin{description}
	\item[n] same convoys
	\item[cpm] maintenance cost per month for each convoy
	\item[cpd] maintenance cost per $km$ for each convoy
	\item[v] average velocity of each convoy
	\item[q] cargo load of each convoy
	\item[l] distance that goods must be transferred
	\item[$\frac{\Delta Q}{\Delta T}$] as the  production or consumption rate or a determined  portion of them
	\item[ppd] reward for eah unit of goods transferred 1 $km$
	\item[dstCoeff] multiplier of euclidean distance to estimate the not straight route of convoys 
\end{description}

Cost at \eqref{cost_per_distance} is calculated as if the euclidean distance of industries were covered with the slower average speed. Duration is right but they cover the larger actual distance in that time. Subsequently, cost, for $n$ convoys, actually is
\[n*Cpd *dstCoeff\]
So, substituting $Cpd$ from \eqref{cost_per_distance} for $n$ convoys, Revenue per month is estimated as
\begin{equation}\label{Revenue_per_month}
	Revenue = ppd*l*\frac{\Delta Q}{\Delta T} - n*(\dfrac{cpd*l}{L}*dstCoeff+cpm)
\end{equation}

 We see that the only variables in the above formula is the number $n$ of convoys and the average time $L$ that they need to reach their destination.
 If $n$ convoys, for any reason, create a transportation with lesser momentum than that it is asked for, then, by using \eqref{convoy-q}, the revenue per month is given by
 \[	Revenue = n*\left(ppd*l*\frac{q}{2*L} - ( \dfrac{cpd*l}{L}*dstCoeff+cpm)\right) \]
 In formula \eqref{Revenue_per_month}, $L$ is $L(l,\bar{v})$ calculated by \eqref{loop-length}.
\tableofcontents
\end{document}
	