mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-24 17:10:36 +00:00
edge_weights table for better cost computation
This commit is contained in:
parent
e3816fbcb8
commit
b09dae8437
@ -26,6 +26,7 @@ vector<int> hubval;
|
||||
|
||||
vector<edgeinfo> sagedges;
|
||||
vector<vector<int>> edges_yes, edges_no;
|
||||
vector<vector<pair<int, double>>> edge_weights;
|
||||
|
||||
ld edgepower=1, edgemul=1;
|
||||
|
||||
@ -53,6 +54,14 @@ void prepare_graph() {
|
||||
edges_no[i].push_back(j);
|
||||
}
|
||||
|
||||
edge_weights.clear(); edge_weights.resize(DN);
|
||||
for(auto& e: sagedges) {
|
||||
if(e.i == e.j) continue;
|
||||
e.weight2 = pow((double) e.weight, (double) edgepower) * edgemul;
|
||||
edge_weights[e.i].emplace_back(e.j, e.weight2);
|
||||
edge_weights[e.j].emplace_back(e.i, e.weight2);
|
||||
}
|
||||
|
||||
sagnode.clear();
|
||||
sagnode.resize(isize(sagcells), -1);
|
||||
for(int i=0; i<DN; i++)
|
||||
@ -99,13 +108,7 @@ void create_viz() {
|
||||
state |= SS_GRAPH;
|
||||
|
||||
if(!vact) for(int i=0; i<DN; i++) vdata[i].data = 0;
|
||||
if(!vact) for(int i=0; i<isize(sagedges); i++) {
|
||||
edgeinfo& ei = sagedges[i];
|
||||
|
||||
ei.weight2 = pow((double) ei.weight, (double) edgepower) * edgemul;
|
||||
|
||||
addedge0(ei.i, ei.j, &ei);
|
||||
}
|
||||
if(!vact) for(auto& e: sagedges) addedge0(e.i, e.j, &e);
|
||||
|
||||
if(sagcells[0].first == nullptr) return;
|
||||
|
||||
|
@ -45,13 +45,11 @@ double costat(int vid, int sid) {
|
||||
}
|
||||
|
||||
case smMatch: {
|
||||
vertexdata& vd = vdata[vid];
|
||||
for(int j=0; j<isize(vd.edges); j++) {
|
||||
edgeinfo *ei = vd.edges[j].second;
|
||||
int t2 = vd.edges[j].first;
|
||||
for(auto& e: edge_weights[vid]) {
|
||||
auto t2 = e.first;
|
||||
if(sagid[t2] != -1) {
|
||||
ld cdist = sagdist[sid][sagid[t2]];
|
||||
ld expect = match_a / ei->weight2 + match_b;
|
||||
ld expect = match_a / e.second + match_b;
|
||||
ld dist = cdist - expect;
|
||||
cost += dist * dist;
|
||||
}
|
||||
@ -60,11 +58,9 @@ double costat(int vid, int sid) {
|
||||
}
|
||||
|
||||
case smClosest: {
|
||||
vertexdata& vd = vdata[vid];
|
||||
for(int j=0; j<isize(vd.edges); j++) {
|
||||
edgeinfo *ei = vd.edges[j].second;
|
||||
int t2 = vd.edges[j].first;
|
||||
if(sagid[t2] != -1) cost += sagdist[sid][sagid[t2]] * ei->weight2;
|
||||
for(auto& e: edge_weights[vid]) {
|
||||
auto t2 = e.first;
|
||||
if(sagid[t2] != -1) cost += sagdist[sid][sagid[t2]] * e.second;
|
||||
}
|
||||
|
||||
if(!hubval.empty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user