MacTech Network:   MacTech Forums  |  MacForge.net  |  Computer Memory  |  Register Domains  |  Cables  |  iPod Deals  | Mac Deals  | Mac Book Shelf


  MacTech Magazine

The journal of Macintosh technology

 
 

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  MacTech Forums  
  Get a copy of MacTech RISK FREE  
MacTech Only Search:
Community Search:
MacTech Central
  by Category  
  by Company  
  by Product  
MacTech News
  MacTech News  
  Previous News  
  MacTech RSS  
Article Archives
  Show Indices  
  by Volume  
  by Author  
  Source Code FTP  
Inside MacTech
  Writer's Kit  
  Editorial Staff  
  Editorial Calendar  
  Back Issues  
  Advertising  
Contact Us
  Customer Service  
  MacTech Store  
  Legal/Disclaimers  
  Webmaster Feedback  
 Get Netflix

 April 1999 Programmer's Challenge

Shortest Network

Mail solutions to: progchallenge@mactech.com
Due Date: 11:59pm ET, Thursday, 1 April 1999

This month’s problem was suggested by Michael Kennedy, who wins two Challenge points for making the suggestion. The problem is to find the shortest network of line segments interconnecting a specified set of points. Shortest network algorithms have obvious practical application in constructing transportation and communications networks. In a January 1989, Scientific American article, Marshall Bern and Ronald Graham discussed the shortest network "Steiner" problem as one of a class of NP-hard problems. While no polynomial-time algorithm is known, the article (which, unfortunately, I have not been able to find online) discusses practical algorithms that produce networks slightly longer than the optimal one. Your Challenge for this month is to produce a near-optimal network in minimum time. Fortunately, we have been granted unlimited power of eminent domain, so there are no restrictions on where intermediate nodes may be placed or where connections may be routed.

The prototype for the code you should write is:

#if defined(__cplusplus)
extern "C" {
#endif

typedef struct Node {  /* node coordinates */
  double x;
  double y;
} Node;

typedef struct Connection {   /* connection between Node[index1] and Node[index2] */
  long index1;
  long index2;
} Connection;

long /* numConnections */ ShortestNetwork(
  long numInitialNodes,       /* number of nodes to connect */
  long *numIntermediateNodes, /* number of nodes added by ShortestNetwork */
  Node nodes[],               /* Nodes 0..numInitialNodes-1 are initialized on entry. */
                              /* Nodes numInitialNodes..numInitialNodes+*numIntermediateNodes-1 are added by ShortestNetwork */
  Connection connections[],   /* connections between nodes */
  long maxNodes,              /* number of entries allocated for nodes */
  long maxConnections         /* number of entries allocated for connections */
);

#if defined(__cplusplus)
}
#endif

Your ShortestNetwork routine will be given a list of numInitialNodes nodes to connect. You may add intermediate nodes to help you form a shorter network, and must produce as output a list of connections between pairs of nodes. The connections must provide a path between any pair of the initial nodes.

Your solution must return the number of intermediate nodes added to the network in *numIntermediateNodes, while storing the location of those nodes in nodes[numInitialNodes+k], k=0..*numIntermediateNodes-1. A connection is specified by storing the indices of the two nodes being connected into the connection array. Your ShortestNetwork routine should return the number of connections created.

The maxNodes and maxConnections parameters indicate how much storage has been allocated for nodes and connections. It is my intention to allocate enough storage for all the nodes and connections your solution might create, but if it turns out that there is not enough storage, your solution should return a value of —1 to indicate that storage was exhausted.

The winner will be the solution that generates the shortest network in the minimum amount of time. Specifically, your solution will be assigned a cost equal to the sum of the distances between nodes in your list of connections, plus a penalty of 10% for each second of execution time. Solutions that do not connect all of the initial nodes will be penalized with a very large cost. The solution with the lowest total cost over a series of networking problems will be the winner.

This will be a native PowerPC Challenge, using the latest CodeWarrior environment. Solutions may be coded in C, C++, or Pascal. Thanks to Michael for suggesting this Challenge.


Test code for this Challenge is available.


You can get a head start on the Challenge by reading the Programmer's Challenge mailing list. It will be posted to the list on or before the 12th of the preceding month. To join, send an email to listserv@listmail.xplain.com with the subject "subscribe challenge-A". You can also join the discussion list by sending a message with the subject "subscribe challenge-D".





Generate a short URL for this page:


Click on the cover to
see this month's issue!

TRIAL SUBSCRIPTION
Get a RISK-FREE subscription to the only technical Mac magazine!

Today's Deal


Apple Special

Order
Snow Leopard,
Mac Box Set, Family Pack,
and Snow Leopard Server
at a discount.
 


MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797

Register Low Cost (ok dirt cheap!) Domain Names in the MacTech Domain Store. As low as $1.99!
Save on long distance * Upgrade your Computer. See local info about Westlake Village
appleexpo.com | bathjot.com | bathroomjot.com | bettersupplies.com | comclothing.com | computerlunatics.com | dotcomclothing.com | explainit.com | exposinternational.com | homeismycastle.com | hoodcards.com | intlexpo.com | keyinfocard.com | kosheru.com | learnmorsels.com | localdealcards.com | lvschools.com | macjobsearch.com | mactechjobs.com | mactechmonitor.com | mactechsupplies.com | macwishbook.com | movie-depot.com | netprofessional.com | nibblelearning.com | notesintheshower.com | officejot.com | onlinebigbox.com | palmosdepot.com | peopleslineitemveto.com | showerjot.com | snapestore.com | snapishop.com | snapistore.com | snaptradingpost.com | stimulusmap.com | stimulusroadmap.com | triunfoguides.com | video-depot.com
Staff Site Links



All contents are Copyright 1984-2008 by Xplain Corporation. All rights reserved.

MacTech is a registered trademark of Xplain Corporation. Xplain, Video Depot, Movie Depot, Palm OS Depot, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, NetProLive, JavaTech, WebTech, BeTech, LinuxTech, Apple Expo, MacTech Central and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.