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 6556261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:55:20+00:00 2026-05-25T12:55:20+00:00

I have an assignment that I’m trying to do using Java, but I am

  • 0

I have an assignment that I’m trying to do using Java, but I am confused about how to set up/what is the nodes for the following graph. Basically, it is the pen plotter problem, or more commonly known as the travelling salesman problem. Where my following input is:

Line between 4 1 and 4 4    
Line between 4 4 and 4 7    
Line between 2 6 and 4 4   
Line between 4 4 and 6 2  
Line between 6 6 and 4 4   
Line between 2 2 and 4 4   

and my output comes out as:

<n> nodes explored
cost = 24.61
Move from 0 0 to 2 2
Draw from 2 2 to 4 4
Draw from 4 4 to 6 6
Move from 6 6 to 4 7
Draw from 4 7 to 4 4
Draw from 4 4 to 4 1
Move from 4 1 to 6 2
Draw from 6 2 to 4 4
Draw from 4 4 to 2 6

Assuming that the bottom left hand corner of the piece of paper, would be your start (0,0) and it goes up in coordinates, are each coordinate a node, and how would I determine when to move and draw a line. I know I should be using an undirected graph with A* but I’m still quite confused about which ones are nodes (vertices) and how I’d determine when to move and when to draw lines, could someone give me some advice?

EDIT: note that the refers to the amount/number of nodes explored throughout the whole search.

  • 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-25T12:55:20+00:00Added an answer on May 25, 2026 at 12:55 pm

    To use A*, you will first need an admissible heuristic function. [explanation what it is is attached at the end of this answer].

    Problem as a Graph for A:*

    define G=(V,E) as your graph, such that:

    V={all possible drawings prefixes} [i.e. all possible ‘snap-shots’ of each possible draw]. note you shouldn’t hold this graph in memory, but create it on the fly, with next() which will be explained later. [note that practically, for each state you actually need to store only (1)where is the pen currently (2)which lines where already drawn]

    E={all possible changes from one 'snap shot' to another}

    You also need w:E->R [a weight function] which will be simply: w(point1,point2)=euclidian_distance(point1,point2)

    You should also define next:V->P(V): next(v)={all snap shots you can get from v, using exactly one move/draw

    Finally, you should also define F: all “ending” states. F={all the prefixes which all the lines are drawn}

    How to run A*:

    start from the snapshot where your pen is at (0,0), and no lines are drawn [this is the initial state], and keep going until you find one of the final states. when you do, if your heuristic is valid, you are guaranteed to have got the optimized solution, because A* is admissible and optimized

    (*) admissible heuristic function:

    let h*(v)=real distance to target from vertex v.

    a heuristic function h:V->R is admissible if h(v)<=h*(v) for each v in V

    Your real Challenge

    The hard part for TSP is finding a an admissible h. It is so hard because you have no idea what’s the shortest path is, and if the heuristic function is not admissible, it is not guaranteed that the solution found will be optimized.

    Suggestion:

    You might want to use some any time algorithm, When I did something similar to this, [solved TSP with multiple agents] I also used A*, but started with a non valid heuristic, and iteratively decreased it, so if I had enough time, I found optimal solution, and if not – I returned the best solution I could find.

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

Sidebar

Related Questions

I have a simple assignment that the professor wants us to do. Basically to
I have this assignment that I've tried. But when I enter 1 it should
I have an assignment that is the following: For a given integer array, find
I have an assignment that has asked me to copy a file using buffered
I currently have a school assignment that involves both PHP and asp.net. Now the
I'm working on an assignment that is telling me to assume that I have
I have an assignment in a language-independent class, and part of it is using
I have an assignment that requires us to implement a doubly linked list class.
I have an assignment that converts dates from one calendar system to another. The
I have this assignment due that requires the usage of FLTK. The code is

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.