Replaced costs array with just a single cost value
This commit is contained in:
+21
-35
@@ -20,17 +20,13 @@ bool isEmpty(const std::vector<T> & vec, int columnCount) {
|
||||
}
|
||||
|
||||
|
||||
float* StepParityCost::getActionCost(State * initialState, State * resultState, std::vector<Row>& rows, int rowIndex)
|
||||
float StepParityCost::getActionCost(State * initialState, State * resultState, std::vector<Row>& rows, int rowIndex)
|
||||
{
|
||||
Row &row = rows[rowIndex];
|
||||
int columnCount = row.columnCount;
|
||||
float elapsedTime = resultState->second - initialState->second;
|
||||
|
||||
float* costs = new float[NUM_Cost];
|
||||
for(int i = 0; i < NUM_Cost; i++)
|
||||
{
|
||||
costs[i] = 0;
|
||||
}
|
||||
float cost = 0;
|
||||
|
||||
std::vector<StepParity::Foot> combinedColumns(columnCount, NONE);
|
||||
|
||||
@@ -63,11 +59,6 @@ float* StepParityCost::getActionCost(State * initialState, State * resultState,
|
||||
}
|
||||
}
|
||||
|
||||
costs[COST_MINE] += calcMineCost( initialState, resultState, row, combinedColumns, columnCount);
|
||||
costs[COST_HOLDSWITCH] += calcHoldSwitchCost( initialState, resultState, row, combinedColumns, columnCount);
|
||||
costs[COST_BRACKETTAP] += calcBracketTapCost( initialState, resultState, row, leftHeel, leftToe, rightHeel, rightToe, elapsedTime, columnCount);
|
||||
// costs[COST_OTHER] += calcMovingFootWhileOtherIsntOnPadCost( initialState, resultState, columnCount);
|
||||
|
||||
bool movedLeft =
|
||||
resultState->didTheFootMove[LEFT_HEEL] ||
|
||||
resultState->didTheFootMove[LEFT_TOE];
|
||||
@@ -87,26 +78,23 @@ float* StepParityCost::getActionCost(State * initialState, State * resultState,
|
||||
(initialState->didTheFootMove[RIGHT_TOE] &&
|
||||
!initialState->isTheFootHolding[RIGHT_TOE]));
|
||||
|
||||
// jacks don't matter if you did a jump before
|
||||
|
||||
bool jackedLeft = didJackLeft(initialState, resultState, leftHeel, leftToe, movedLeft, didJump, columnCount);
|
||||
bool jackedRight = didJackRight(initialState, resultState, rightHeel, rightToe, movedRight, didJump, columnCount);
|
||||
|
||||
// Doublestep weighting doesn't apply if you just did a jump or a jack
|
||||
|
||||
costs[COST_BRACKETJACK] += calcBracketJackCost( initialState, resultState, rows, rowIndex, movedLeft, movedRight, jackedLeft, jackedRight, didJump, columnCount);
|
||||
costs[COST_DOUBLESTEP] += calcDoublestepCost(initialState, resultState, rows, rowIndex, movedLeft, movedRight, jackedLeft, jackedRight, didJump, columnCount);
|
||||
// costs[COST_JUMP] += calcJumpCost( row, movedLeft, movedRight, elapsedTime, columnCount);
|
||||
costs[COST_SLOW_BRACKET] += calcSlowBracketCost(row, movedLeft, movedRight, elapsedTime);
|
||||
costs[COST_TWISTED_FOOT] += calcTwistedFootCost(resultState);
|
||||
costs[COST_FACING] += calcFacingCosts( initialState, resultState, combinedColumns, columnCount);
|
||||
costs[COST_SPIN] += calcSpinCosts(initialState, resultState, combinedColumns, columnCount);
|
||||
costs[COST_FOOTSWITCH] += caclFootswitchCost( initialState, resultState, row, combinedColumns, elapsedTime, columnCount);
|
||||
costs[COST_SIDESWITCH] += calcSideswitchCost( initialState, resultState, columnCount);
|
||||
costs[COST_MISSED_FOOTSWITCH] += calcMissedFootswitchCost( row, jackedLeft, jackedRight, columnCount);
|
||||
costs[COST_JACK] += calcJackCost( movedLeft, movedRight, jackedLeft, jackedRight, elapsedTime, columnCount);
|
||||
costs[COST_DISTANCE] += calcBigMovementsQuicklyCost( initialState, resultState, elapsedTime, columnCount);
|
||||
// costs[COST_CROWDED_BRACKET] += calcCrowdedBracketCost(initialState, resultState, elapsedTime, columnCount);
|
||||
cost += calcMineCost( initialState, resultState, row, combinedColumns, columnCount);
|
||||
cost += calcHoldSwitchCost( initialState, resultState, row, combinedColumns, columnCount);
|
||||
cost += calcBracketTapCost( initialState, resultState, row, leftHeel, leftToe, rightHeel, rightToe, elapsedTime, columnCount);
|
||||
cost += calcBracketJackCost( initialState, resultState, rows, rowIndex, movedLeft, movedRight, jackedLeft, jackedRight, didJump, columnCount);
|
||||
cost += calcDoublestepCost(initialState, resultState, rows, rowIndex, movedLeft, movedRight, jackedLeft, jackedRight, didJump, columnCount);
|
||||
cost += calcSlowBracketCost(row, movedLeft, movedRight, elapsedTime);
|
||||
cost += calcTwistedFootCost(resultState);
|
||||
cost += calcFacingCosts( initialState, resultState, combinedColumns, columnCount);
|
||||
cost += calcSpinCosts(initialState, resultState, combinedColumns, columnCount);
|
||||
cost += caclFootswitchCost( initialState, resultState, row, combinedColumns, elapsedTime, columnCount);
|
||||
cost += calcSideswitchCost( initialState, resultState, columnCount);
|
||||
cost += calcMissedFootswitchCost( row, jackedLeft, jackedRight, columnCount);
|
||||
cost += calcJackCost( movedLeft, movedRight, jackedLeft, jackedRight, elapsedTime, columnCount);
|
||||
cost += calcBigMovementsQuicklyCost( initialState, resultState, elapsedTime, columnCount);
|
||||
|
||||
// I don't like that we're updating columns here like this.
|
||||
// We're basically updating columns with the final position of the feet
|
||||
@@ -119,12 +107,8 @@ float* StepParityCost::getActionCost(State * initialState, State * resultState,
|
||||
resultState->whereTheFeetAre[combinedColumns[i]] = i;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < COST_TOTAL; i++)
|
||||
{
|
||||
costs[COST_TOTAL] += costs[i];
|
||||
}
|
||||
|
||||
return costs;
|
||||
return cost;
|
||||
}
|
||||
|
||||
// This merges the `columns` properties of initialState and resultState, which
|
||||
@@ -172,7 +156,8 @@ void StepParityCost::mergeInitialAndResultPosition(State * initialState, State *
|
||||
|
||||
// Calculate the cost of avoiding a mine before the current step
|
||||
// If a mine occurred just before a step, add to the cost
|
||||
// ex: 00M0
|
||||
// ex:
|
||||
// 00M0
|
||||
// 0010 <- add cost
|
||||
//
|
||||
// 00M0
|
||||
@@ -225,7 +210,8 @@ float StepParityCost::calcHoldSwitchCost(State * initialState, State * resultSta
|
||||
|
||||
// Calculate the cost of tapping a bracket during a hold note
|
||||
//
|
||||
// ex: 0200
|
||||
// ex:
|
||||
// 0200
|
||||
// 0000
|
||||
// 1000 <- maybe bracketable, if left heel is holding Down arrow
|
||||
// 0300
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace StepParity
|
||||
/// @param rows
|
||||
/// @param rowIndex The index of the row represented by resultState
|
||||
/// @return The computed cost
|
||||
float* getActionCost(State * initialState, State * resultState, std::vector<Row> &rows, int rowIndex);
|
||||
float getActionCost(State * initialState, State * resultState, std::vector<Row> &rows, int rowIndex);
|
||||
|
||||
private:
|
||||
void mergeInitialAndResultPosition(State * initialState, State * resultState, std::vector<StepParity::Foot> &combinedColumns, int columnCount);
|
||||
|
||||
@@ -273,12 +273,8 @@ Json::Value StepParityNode::ToJson()
|
||||
Json::Value n;
|
||||
n["id"] = it->first->id;
|
||||
Json::Value jsonCosts;
|
||||
float * costs = it->second;
|
||||
for(int i = 0; i < NUM_Cost; i++)
|
||||
{
|
||||
jsonCosts[COST_LABELS[i]] = costs[i];
|
||||
}
|
||||
n["costs"] = jsonCosts;
|
||||
float cost = it->second;
|
||||
n["cost"] = cost;
|
||||
jsonNeighbors.append(n);
|
||||
}
|
||||
root["id"] = id;
|
||||
|
||||
@@ -282,14 +282,10 @@ namespace StepParity {
|
||||
State state;
|
||||
|
||||
// Connections to, and the cost of moving to, the connected nodes
|
||||
std::unordered_map<StepParityNode *, float*> neighbors;
|
||||
std::unordered_map<StepParityNode *, float> neighbors;
|
||||
|
||||
~StepParityNode()
|
||||
{
|
||||
for(auto neighbor: neighbors)
|
||||
{
|
||||
delete[] neighbor.second;
|
||||
}
|
||||
neighbors.clear();
|
||||
}
|
||||
StepParityNode(const State &_state)
|
||||
@@ -342,9 +338,9 @@ namespace StepParity {
|
||||
/// @return
|
||||
StepParityNode *addOrGetExistingNode(const State &state);
|
||||
|
||||
void addEdge(StepParityNode* from, StepParityNode* to, float* costs)
|
||||
void addEdge(StepParityNode* from, StepParityNode* to, float cost)
|
||||
{
|
||||
from->neighbors[to] = costs;
|
||||
from->neighbors[to] = cost;
|
||||
}
|
||||
|
||||
int nodeCount() const
|
||||
|
||||
@@ -61,10 +61,10 @@ void StepParityGenerator::buildStateGraph()
|
||||
for(auto it = PermuteFootPlacements->begin(); it != PermuteFootPlacements->end(); it++)
|
||||
{
|
||||
State resultState = initResultState(state, row, *it);
|
||||
float* costs = costCalculator.getActionCost(&state, &resultState, rows, i);
|
||||
float cost = costCalculator.getActionCost(&state, &resultState, rows, i);
|
||||
resultState.calculateHashes();
|
||||
StepParityNode *resultNode = graph.addOrGetExistingNode(resultState);
|
||||
graph.addEdge(initialNode, resultNode, costs);
|
||||
graph.addEdge(initialNode, resultNode, cost);
|
||||
if(std::find(uniqueStates.begin(), uniqueStates.end(), resultState) == uniqueStates.end())
|
||||
{
|
||||
uniqueStates.push_back(resultState);
|
||||
@@ -90,12 +90,7 @@ void StepParityGenerator::buildStateGraph()
|
||||
{
|
||||
State state = previousStates.front();
|
||||
StepParityNode *node = graph.addOrGetExistingNode(state);
|
||||
float * emptyCosts = new float[NUM_Cost];
|
||||
for(int i = 0; i < NUM_Cost; i++)
|
||||
{
|
||||
emptyCosts[i] = 0;
|
||||
}
|
||||
graph.addEdge(node, endNode, emptyCosts);
|
||||
graph.addEdge(node, endNode, 0);
|
||||
previousStates.pop();
|
||||
}
|
||||
}
|
||||
@@ -247,7 +242,7 @@ std::vector<int> StepParityGenerator::computeCheapestPath()
|
||||
for(auto neighbor: node->neighbors)
|
||||
{
|
||||
int neighbor_id = neighbor.first->id;
|
||||
float weight = neighbor.second[COST_TOTAL];
|
||||
float weight = neighbor.second;
|
||||
if(cost[i] + weight < cost[neighbor_id])
|
||||
{
|
||||
cost[neighbor_id] = cost[i] + weight;
|
||||
|
||||
Reference in New Issue
Block a user