Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:39:57+00:00 2026-05-31T17:39:57+00:00

if f = g + h then where in the below code would I

  • 0

if f = g + h then where in the below code would I add g?

Also, besides adding the movement cost from my initial position, how else can I make this code more efficient?

def a_star(initial_node):
    open_set, closed_set = dict(), list()
    open_set[initial_node] = heuristic(initial_node)
    while open_set:
        onode = get_next_best_node(open_set)
        if onode == GOAL_STATE:
            return reconstruct_path(onode)
        del open_set[onode]
        closed_set.append(onode)
        for snode in get_successor_nodes(onode):
            if snode in closed_set:
                continue
            if snode not in open_set:
                open_set[snode] = heuristic(snode)
                self.node_rel[snode] = onode
    return False
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:39:58+00:00Added an answer on May 31, 2026 at 5:39 pm

    In the last if, if snode is not in open_set (no pun intended!) you shouldn’t set just the heuristic, but the heuristic plus the cost of the current node. And if snode is in the open set, you should check the minimum between the present value and the current one (if there are two or more ways to reach the same node, the least costly one should be considered).

    That means you need to store both the node’s “actual” cost and the “estimated” cost. The actual cost of the initial node is zero. For every new node, it’s the minimum for every incoming arc between the cost of the other vertex plus the cost of the arc (in other words, the cost of the last node plus the cost to move from that to the current one). The estimated cost would have to sum both values: the actual cost so far plus the heuristic function.

    I don’t know how the nodes are represented in your code, so I can’t give advice more specific than that. If you still have doubt, please edit your question providing more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple WCF service, that worked fine (code below), then
The code below shows a rectangle class using double points, which are also stored
Can anyone help transform/provide a skeleton of how to transform the below code to
The routine below inserts a page, sets permalinks to postname then attempts to update
Is better to use the below statement Convert.ToInt32(0 + stringValue) If not then why?
After a user adds 5 emails and their name to form below, and then
For some weird reason, the codes below are first working, then website is redirecting
Then: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBoxList1.Items.Add(new ListItem(item1)); CheckBoxList1.Items.Add(new
if strValue = 'Hello' then what would be the value of (strValue <> 'HELLO')
I have the code below that makes a list of div's drag and droppable,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.