У меня есть формула, написанная на C ++, но я пытаюсь преобразовать ее в java, но кажется неправильным, я также пробовал использовать конвертер, но он был неточным, может ли кто-нибудь исправить это для меня ниже
void calculateTrafficIntensity(std::fstream& file, std::vector<double>& aVal, int& linkNumber, int& linkCapacity, int& totalCapacity, int& trafficCases, int& offsetToTi, std::vector<double>& ti, std::vector<double>& Aiti)
{
std::vector<double> Ai;
Ai.reserve(trafficCases);
double onePart, allPortions = 0;
for (int i = 0; i < trafficCases; ++i)
allPortions += Aiti.at(i);
for (double a = aVal.at(0); a <= aVal.at(2); a += aVal.at(1))
{
Ai.clear();
outputMsg(file, "[STATE] Calculating traffic intensity of particular traffic classes, when a = " + std::to_string(a));
onePart = a * totalCapacity / allPortions;
for (int i = 0; i < trafficCases; ++i)
{
Ai.push_back(onePart * Aiti.at(i) / ti.at(i));
outputMsg(file, "A_" + std::to_string(i + 1) + ": " + std::to_string(Ai.back()));
}
calculateBlockingProbability(file, Ai, ti, totalCapacity, trafficCases);
outputMsg(file, "");
}
}
void calculateBlockingProbability(std::fstream& file, std::vector<double>& Ai, std::vector<double>& ti, int& totalCapacity, int& trafficCases)
{
outputMsg(file, "[STATE] Calculating blocking probability");
std::vector<double> Qi;
Qi.resize(static_cast<size_t>(totalCapacity) + 1, 0); // + 1 due to Q(0)
int j;
for (int c = 0; c <= totalCapacity; ++c) // safe to start from 0 and have a zero vector, rather than start from 1 and have ones vector
{
if (!c)
Qi.at(c) = 1.0; // The first one, Q(0)
else
{
for (int i = 0; i < trafficCases; ++i)
{
if (c - ti.at(i) < 0) // Probability is equal to 0
break;
else
j = c - (int)ti.at(i);
Qi.at(c) += Ai.at(i) * ti.at(i) * Qi.at(j) / c;
}
}
}
normalizeBlockingProbability(file, Qi);
}
Теперь код java у меня
public final class RefObject<T>
{
public T argValue;
public RefObject(T refArg)
{
argValue = refArg;
}
}
import java.util.*;
public final class VectorHelper
{
public static <T> void resize(ArrayList<T> list, int newSize)
{
resize(list, newSize, null);
}
public static <T> void resize(ArrayList<T> list, int newSize, T value)
{
if (list.size() > newSize)
{
for (int i = list.size() - 1; i >= newSize; i--)
{
list.remove(i);
}
}
else if (list.size() < newSize)
{
for (int i = list.size(); i < newSize; i++)
{
list.add(value);
}
}
}
public static <T> void swap(ArrayList<T> list1, ArrayList<T> list2)
{
ArrayList<T> temp = new ArrayList<T>(list1);
list1.clear();
list1.addAll(list2);
list2.clear();
list2.addAll(temp);
}
public static <T> ArrayList<T> initializedArrayList(int size, T value)
{
ArrayList<T> temp = new ArrayList<T>();
for (int count = 1; count <= size; count++)
{
temp.add(value);
}
return temp;
}
public static <T> ArrayList<ArrayList<T>> nestedArrayList(int outerSize, int innerSize)
{
ArrayList<ArrayList<T>> temp = new ArrayList<ArrayList<T>>();
for (int count = 1; count <= outerSize; count++)
{
temp.add(new ArrayList<T>(innerSize));
}
return temp;
}
public static <T> ArrayList<ArrayList<T>> nestedArrayList(int outerSize, int innerSize, T value)
{
ArrayList<ArrayList<T>> temp = new ArrayList<ArrayList<T>>();
for (int count = 1; count <= outerSize; count++)
{
temp.add(initializedArrayList(innerSize, value));
}
return temp;
}
}
import java.io.File;
import java.util.*;
public class GlobalMembers {
public static void calculateTrafficIntensity(File file, ArrayList<Double> aVal, RefObject<Integer> linkNumber, RefObject<Integer> linkCapacity, RefObject<Integer> totalCapacity, RefObject<Integer> trafficCases, RefObject<Integer> offsetToTi, ArrayList<Double> ti, ArrayList<Double> Aiti)
{
ArrayList<Double> Ai = new ArrayList<Double>();
Ai.ensureCapacity(trafficCases.argValue);
double onePart;
double allPortions = 0;
for (int i = 0; i < trafficCases.argValue; ++i)
{
allPortions += Aiti.get(i);
}
for (double a = aVal.get(0); a <= aVal.get(2); a += aVal.get(1))
{
Ai.clear();
System.out.println(file + "[STATE] Calculating traffic intensity of particular traffic classes, when a = " + String.valueOf(a));
onePart = a * totalCapacity.argValue / allPortions;
for (int i = 0; i < trafficCases.argValue; ++i)
{
Ai.add(onePart * Aiti.get(i) / ti.get(i));
System.out.println(file + "A_" + String.valueOf(i + 1) + ": " + String.valueOf(Ai.get(Ai.size() - 1)));
}
calculateBlockingProbability(file, Ai, ti, totalCapacity, trafficCases);
System.out.println(file "");
}
}
public static void calculateBlockingProbability(File file, ArrayList<Double> Ai, ArrayList<Double> ti, RefObject<Integer> totalCapacity, RefObject<Integer> trafficCases)
{
System.out.println(file + "[STATE] Calculating blocking probability");
ArrayList<Double> Qi = new ArrayList<Double>();
tangible.VectorHelper.resize(Qi, (size_t)totalCapacity.argValue + 1, 0); // + 1 due to Q(0)
int j;
for (int c = 0; c <= totalCapacity.argValue; ++c) // safe to start from 0 and have a zero vector, rather than start from 1 and have ones vector
{
if (c == 0)
{
Qi.get(c) = 1.0; // The first one, Q(0)
}
else
{
for (int i = 0; i < trafficCases.argValue; ++i)
{
if (c - ti.get(i) < 0) // Probability is equal to 0
{
break;
}
else
{
j = c - (int)ti.get(i);
}
Qi.get(c) += Ai.get(i) * ti.get(i) * Qi.get(j) / c;
}
}
}
normalizeBlockingProbability(file, Qi);
}
}
Заранее спасибо за любую помощь