visual basic barcode program 10: AI-Based Problem Solving in Java

Make PDF417 in Java 10: AI-Based Problem Solving

10: AI-Based Problem Solving
Decoding PDF 417 In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
PDF-417 2d Barcode Creator In Java
Using Barcode printer for Java Control to generate, create PDF 417 image in Java applications.
// Find "optimal" solution using least-cost. import java.util.*; import java.io.*; // Flight information. class FlightInfo { String from; String to; int distance; boolean skip; // used in backtracking FlightInfo(String f, String t, int d) { from = f; to = t; distance = d; skip = false; } } class Optimal { final int MAX = 100; // This array holds the flight information. FlightInfo flights[] = new FlightInfo[MAX]; int numFlights = 0; // number of entries in flight array Stack btStack = new Stack(); // backtrack stack Stack optimal; // holds optimal solution int minDist = 10000; public static void main(String args[]) { String to, from; Optimal ob = new Optimal(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); boolean done = false; FlightInfo f; ob.setup(); try {
PDF-417 2d Barcode Decoder In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
Bar Code Encoder In Java
Using Barcode generator for Java Control to generate, create barcode image in Java applications.
The Art of Java
Barcode Scanner In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
PDF417 Encoder In Visual C#.NET
Using Barcode generation for .NET Control to generate, create PDF 417 image in Visual Studio .NET applications.
System.out.print("From "); from = br.readLine(); System.out.print("To "); to = br.readLine(); do { ob.isflight(from, to); if(ob.btStack.size() == 0) done = true; else { ob.route(to); ob.btStack = new Stack(); } } while(!done); // Display optimal solution. if(ob.optimal != null) { System.out.println("Optimal solution is: "); int num = ob.optimal.size(); for(int i=0; i < num; i++) { f = (FlightInfo) ob.optimal.pop(); System.out.print(f.from + " to "); } System.out.println(to); System.out.println("Distance is " + ob.minDist); } } catch (IOException exc) { System.out.println("Error on input."); } } // Initialize the flight database. void setup() { addFlight("New York", "Chicago", 900); addFlight("Chicago", "Denver", 1000); addFlight("New York", "Toronto", 500); addFlight("New York", "Denver", 1800); addFlight("Toronto", "Calgary", 1700); addFlight("Toronto", "Los Angeles", 2500); addFlight("Toronto", "Chicago", 500); addFlight("Denver", "Urbana", 1000); addFlight("Denver", "Houston", 1000); addFlight("Houston", "Los Angeles", 1500);
Printing PDF-417 2d Barcode In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create PDF417 image in ASP.NET applications.
PDF417 Creator In .NET
Using Barcode encoder for VS .NET Control to generate, create PDF417 image in Visual Studio .NET applications.
10: AI-Based Problem Solving
Drawing PDF 417 In VB.NET
Using Barcode maker for VS .NET Control to generate, create PDF 417 image in Visual Studio .NET applications.
Printing UPC - 13 In Java
Using Barcode drawer for Java Control to generate, create GS1 - 13 image in Java applications.
addFlight("Denver", "Los Angeles", 1000); } // Put flights into the database. void addFlight(String from, String to, int dist) { if(numFlights < MAX) { flights[numFlights] = new FlightInfo(from, to, dist); numFlights++; } else System.out.println("Flight database full.\n"); } // Save shortest route. void route(String to) { int dist = 0; FlightInfo f; int num = btStack.size(); Stack optTemp = new Stack(); for(int i=0; i < num; i++) { f = (FlightInfo) btStack.pop(); optTemp.push(f); // save route dist += f.distance; } // If shorter, keep this route if(minDist > dist) { optimal = optTemp; minDist = dist; } } /* If there is a flight between from and to, return the distance of flight; otherwise, return 0. */ int match(String from, String to) { for(int i=numFlights-1; i > -1; i--) { if(flights[i].from.equals(from) && flights[i].to.equals(to) && !flights[i].skip)
Matrix 2D Barcode Encoder In Java
Using Barcode generation for Java Control to generate, create 2D Barcode image in Java applications.
Generating Code 39 Full ASCII In Java
Using Barcode maker for Java Control to generate, create Code 39 image in Java applications.
The Art of Java
Encoding DUN - 14 In Java
Using Barcode creation for Java Control to generate, create Case Code image in Java applications.
Barcode Maker In Java
Using Barcode creation for BIRT reports Control to generate, create barcode image in BIRT reports applications.
{ flights[i].skip = true; // prevent reuse return flights[i].distance; } } return 0; // not found } // Given from, find any connection using least-cost. FlightInfo find(String from) { int pos = -1; int dist = 10000; // longer than longest route for(int i=0; i < numFlights; i++) { if(flights[i].from.equals(from) && !flights[i].skip) { // Use the shortest flight. if(flights[i].distance < dist) { pos = i; dist = flights[i].distance; } } } if(pos != -1) { flights[pos].skip = true; // prevent reuse FlightInfo f = new FlightInfo(flights[pos].from, flights[pos].to, flights[pos].distance); return f; } return null; } // Determine if there is a route between from and to. void isflight(String from, String to) { int dist; FlightInfo f;
Printing GS1 - 13 In None
Using Barcode encoder for Online Control to generate, create European Article Number 13 image in Online applications.
Printing GTIN - 128 In .NET
Using Barcode encoder for .NET framework Control to generate, create GS1 128 image in .NET framework applications.
10: AI-Based Problem Solving
Creating Linear Barcode In Visual C#.NET
Using Barcode generator for .NET framework Control to generate, create 1D image in .NET framework applications.
UPC Symbol Reader In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
// See if at destination. dist = match(from, to); if(dist != 0) { btStack.push(new FlightInfo(from, to, dist)); return; } // Try another connection. f = find(from); if(f != null) { btStack.push(new FlightInfo(from, to, f.distance)); isflight(f.to, to); } else if(btStack.size() > 0) { // Backtrack and try another connection. f = (FlightInfo) btStack.pop(); isflight(f.from, f.to); } } }
Generate 1D In Visual Studio .NET
Using Barcode encoder for .NET framework Control to generate, create 1D image in VS .NET applications.
GTIN - 128 Creator In None
Using Barcode generation for Office Excel Control to generate, create GS1 128 image in Office Excel applications.
The output from the program is shown here:
From New York To Los Angeles Optimal solution is: New York to Chicago to Denver to Los Angeles Distance is 2900
In this case, the optimal solution is not quite the best one, but it is still a very good one. As explained, when using AI-based searches, the best solution to be found by one search technique will not always be the best solution that exists. You might want to try substituting another search technique in the preceding program, observing what type of optimal solution it finds. The one inefficiency in the preceding method is that all paths are followed to their conclusion. An improved method would stop following a path as soon as the length equaled or exceeded the current minimum. You might want to modify this program to accommodate such an enhancement.
Copyright © OnBarcode.com . All rights reserved.