return result;
}
public static ObjectArrayList findHSSRouteByReduce(ObjectArrayList hss, String hssTempPath) throws IOException
{
ObjectArrayList route = quickFindHSSRoute(hss);
if (isValidHSSRoute(route))
{
return route;
}
IHyperStructure hs = (IHyperStructure) hss.get(0);
ICompactTripletsStructure basicCTS = hs.getBasicCTS();
// Find next tier with one vertex
for (int j = 0; j < basicCTS.getTiers().size(); j++)
{
// TODO Configure hssTempPathReduced using CL options
final String hssTempPathReduced = hssTempPath + "-reduced";
if (j == 0)
{
if (basicCTS.getTier(0).size() > 1)
{
// First reduction
ObjectArrayList structures = new ObjectArrayList();
OpenIntObjectHashMap verticesFromLastTiers = new OpenIntObjectHashMap();
fillVerticesFromLastTier(hss, structures, verticesFromLastTiers);
ObjectArrayList result = new ObjectArrayList();
findIntersectionWithFirstTier(hss, result, structures, verticesFromLastTiers);
ITier firstTier = basicCTS.getTier(0);
IVertex firstTierVertex = (IVertex) result.get(0);
firstTier.intersect(firstTierVertex.getTripletValue());
basicCTS.cleanup(0, 0);
// Unify CTS
ObjectArrayList cts = new ObjectArrayList();
cts.add(((IHyperStructure) hss.get(0)).getBasicCTS());
for (int h = 0; h < hss.size(); h++)
{
hs = (IHyperStructure) hss.get(h);
cts.add(hs.getOtherCTS());
}
unify(cts);
// Update HSS by creating new one (it must be created non-empty)
Properties statistics = new Properties();
hss = createHyperStructuresSystem(cts, statistics);
saveHSS(hssTempPathReduced, hss);
// Check if its possible to find HSS route now
route = quickFindHSSRoute(hss);
if (isValidHSSRoute(route))
{
return route;
}
// Route not found. Reduce next tier
// Basic CTS may have been changed in newly created HSS
if (!basicCTS.getPermutation().sameAs(((IHyperStructure) hss.get(0)).getBasicCTS().getPermutation()))
{
// Basic CTS changed
j = -1;
basicCTS = ((IHyperStructure) hss.get(0)).getBasicCTS();
}
}
continue;
}
ITier tier = basicCTS.getTier(j);
if (tier.size() > 1)
{
// Previous tier contains one vertex
OpenIntObjectHashMap prevTier = (OpenIntObjectHashMap) ((IHyperStructure)hss.get(0)).getTiers().get(j - 1);
IVertex prevVertex = (IVertex) prevTier.values().get(0);
if (prevVertex.hasEmptyBottomEdge())
{
// If previous vertex contains only one bottom vertex
// then we should keep that vertex (and move forward to reduce next HSS tier?)
if (prevVertex.getBottomVertex1() != null)
{
tier.intersect(prevVertex.getBottomVertex1().getTripletValue());
}
else if (prevVertex.getBottomVertex2() != null)
{
tier.intersect(prevVertex.getBottomVertex2().getTripletValue());
}
basicCTS.cleanup(j, j);
// Unify CTS
ObjectArrayList cts = new ObjectArrayList();
cts.add(((IHyperStructure) hss.get(0)).getBasicCTS());
for (int h = 0; h < hss.size(); h++)
{
hs = (IHyperStructure) hss.get(h);
cts.add(hs.getOtherCTS());
}
unify(cts);
// Update HSS by creating new one (it must be created non-empty)
Properties statistics = new Properties();
hss = createHyperStructuresSystem(cts, statistics);
saveHSS(hssTempPathReduced, hss);
// Check if its possible to find HSS route now
route = quickFindHSSRoute(hss);
if (isValidHSSRoute(route))
{
return route;
}
// Route not found. Reduce next tier
// Basic CTS may have been changed in newly created HSS
if (!basicCTS.getPermutation().sameAs(((IHyperStructure) hss.get(0)).getBasicCTS().getPermutation()))
{
// Basic CTS changed
j = -1;
basicCTS = ((IHyperStructure) hss.get(0)).getBasicCTS();
}
}
else
{
LOGGER.info("Backup HSS to {}...", hssTempPath);
saveHSS(hssTempPath, hss);
ITripletValue bottomVertex1TripletValue = prevVertex.getBottomVertex1().getTripletValue();
ITripletValue bottomVertex2TripletValue = prevVertex.getBottomVertex2().getTripletValue();
tier.intersect(bottomVertex1TripletValue);
try
{
basicCTS.cleanup(j, j);
// Unify CTS
ObjectArrayList cts = new ObjectArrayList();
cts.add(((IHyperStructure) hss.get(0)).getBasicCTS());
for (int h = 0; h < hss.size(); h++)
{
hs = (IHyperStructure) hss.get(h);
cts.add(hs.getOtherCTS());
}
unify(cts);
// Update HSS by creating new one (it must be created non-empty)
Properties statistics = new Properties();
hss = createHyperStructuresSystem(cts, statistics);
}
catch (EmptyStructureException e)
{
// If HSS was built empty then
// restore HSS and keep vertex from bottomVertex2
LOGGER.info("Restore HSS from backup {}", hssTempPath);
hss = loadHSS(hssTempPath);
LOGGER.info("done");
basicCTS = ((IHyperStructure) hss.get(0)).getBasicCTS();
tier = basicCTS.getTier(j);
tier.intersect(bottomVertex2TripletValue);
basicCTS.cleanup(j, j);
// Unify CTS
ObjectArrayList cts = new ObjectArrayList();
cts.add(((IHyperStructure) hss.get(0)).getBasicCTS());
for (int h = 0; h < hss.size(); h++)
{
hs = (IHyperStructure) hss.get(h);
cts.add(hs.getOtherCTS());
}
unify(cts);
// Update HSS by creating new one (it must be created non-empty)
Properties statistics = new Properties();
hss = createHyperStructuresSystem(cts, statistics);