Suggestions about interface: graph, directed and undirected graph

Hello all,
I'm having some doubts about the right 'choice' of interfaces. I'm designing a little library for graphs and I was thinking about the difference between directed and undirected graphs, and how I should reflect this in the library. My apologies for my bad English.
There is a small, but elegant, difference between directed and undirected graphs. Therefor, I don't know if it's worth to distuingish this difference in interfaces or not. I'll explain the difference by example. Usually, you can ask a directed graph the following queries:
- all out-edges of a node + the total of such edges (outdegree)
- all in-edges of a node + indegree
- the successors of a node
- the predecessors of a node
The same questions can be asked to a undirected graph, but the in-edges and the out-edges of a node are equal, the successors and the predecessors are equal, etc... Thats basically the only difference between directed and undirected graphs.
I found some solutions to define graphs, directed graphs and undirected graphs by means of interfaces.
[1] one interface, duplicate methods, no tagging interfaces
public interface Graph {
    Set getOutEdges(Node node);
    int getOutDegree(Node node);
    Set getinEdges(Node node);
    int getinDegree(Node node);
    Set getSuccessors(Node node);
    Set getPredecessor(Node node);
    boolean isDirected(); // no tagging interface
}[2] one interface, duplicate methods, tagging interfaces
public interface Graph {
    Set getOutEdges(Node node);
    int getOutDegree(Node node);
    Set getinEdges(Node node);
    int getinDegree(Node node);
    Set getSuccessors(Node node);
    Set getPredecessor(Node node);
public DirectedGraph extends Graph { } // tagging interface
public UndirectedGraph extends Graph { } // tagging interface[3] three interfaces
public interface Graph {
public interface DirectedGraph extends Graph {
    Set getOutEdges(Node node);
    int getOutDegree(Node node);
    Set getinEdges(Node node);
    int getinDegree(Node node);
    Set getSuccessors(Node node);
    Set getPredecessor(Node node);
public interface UndirectedGraph extends Graph {
    Set getTouchingEdges(Node node);
    int getdegree(Node node);
    Set getNeighbors(Node node);
}In the first solution, you dont know at compile time whether a graph is directed or undirected. However, it is very elegant for algorithms, since a lot of algorithms work for directed and undirected graphs. The main disadvantage of this solution is that you have duplicate functions in case of of undirected graphs: getOutEdges and getInEdges return the same set, etc.
The difference between the first and the second solution is that the second solutions gives a way to detect whether a graph is directed or undirected at compile-time.
The third solution has two seperate interfaces. This is much logical, and you know the graphtype at compile-time. However, this approach might lead to bloated code, as the algoritms for undirected and directed graphs now have two graphtypes (this can ofcourse be fixed by itroducing some kind of decorator, which in fact simulates the first solution).
As I don't have much experience in design, I can't forsee any big problems or disadvantes of one of the approaches. Therefor, I would like to ask for your opinion. What approach is most common and best practice?
Thanks in advance.

I would tend to go with true inheritance for this case. There is a strong ISA relationship between a graph and uni-directional and bi-directional graphs. Programming to an interface (as in the Lyskov substitution principle) will give you a parallel heirachy of interfaces and implementations. This can become a problem if you start out not knowing what interface needs to be published, but in the case of graphs this should not be a problem. With a heirachy all the shared code can be written once. In this case the specialized code will just simplify calling more general code in the parent class.
If all your graphs fit into memory then the implemenation should not be a problem. I used to work with map data where the graph does not fit into memory. Then you have to be careful about your interface or you will be getting calls that cannot be properly optimized "behind the scenes". Another specialization is in game programming where nodes are not actually expanded until they are "arrived at". Then you have to keep information about what parts of the structure are fleshed out and which are provisional.

Similar Messages

  • Docs about Interfaces between CO and BW/BI

    Hi all Gurus,
    I am just looking for documents about Interfaces between FI/CO and BW/BI. Can any body provide me the required documents. It is very urgent....  [email protected]
    Thanks in advance
    SIM
    Edited by: SIM on Feb 22, 2008 12:19 PM

    Hi
    You are right. I meant the interfaces between FI/CO and BW/BI. Namely how do we build the Interfaces such as IDOC and other interfaces between them. I need practice oriented docs with all steps towards building interfaces.
    Thanks
    SIM

  • How create graphs(pie and bar graphs) in j2me

    hi friends,
    how to create graphs in j2me?
    plz help me.
    regards,
    Shruthi R S

    Hi Shruti,
    I have developed the same application in j2me. I worked on graphs related to stocks. So i think my code can work for u too.
    Here is the code for displaying bars:
    package project;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
    class BarCanvas extends Canvas {
         public static boolean indicator=true;
         public static int lenght=120;
         int pad=2;
         Font font;
         private int fh;
         String xName = "";
         String yName = "VALUE";
         private int xmargen=15;
         private int ymargen=15;
         private int initialx=0;
         private int initialy=0;
         int scale = 15;
         private int bw=0;
         int index=0;
         int scaleincr;
         int padincr;
         int pady=0;
         String s1;
         //int bars[]={20,30,40,40,50,20,70,80,90};
         int bars[]={20,30,40,50,300};
         int k=bars.length;
         int barinc=scale+bw+pad;
              BarCanvas(String s1){
                   this.s1=s1;
                   font = Font.getFont(Font.FACE_SYSTEM,
                   Font.STYLE_PLAIN, Font.SIZE_SMALL);
                   fh = font.getHeight();
                   if(s1.equals("Tic"))
                        padincr=2;
                        bw=3;
                        scaleincr=3;
                   if(s1.equals("1 minute"))
                        padincr=2;
                        bw=3;
                        scaleincr=3;
                   if(s1.equals("5 minutes"))
                        padincr=2;
                        bw=3;
                        scaleincr=15;
                   if(s1.equals("15 minutes"))
                        padincr=10;
                        bw=5;
                        scaleincr=15;
                   if(s1.equals("Hourly"))
                        padincr=10;
                        bw=5;
                        scaleincr=1;
                   if(s1.equals("Daily"))
                        padincr=10;
                        bw=5;
                        scaleincr=1;
                   if(s1.equals("Weekly"))
                        padincr=10;
                        bw=5;
                        scaleincr=1;
                   }//linecanvas
    public void paint(Graphics g) {
                        int width = getWidth();
                   int height = getHeight();
                   int titleHeight;
                   g.setFont(font);
                   int titlex1 = font.stringWidth("TIME");
                   int titlex = (width-titlex1)/2;
                   g.setColor(0,0,0);
                   g.fillRect(0, 0, width, height);
                   //set text on scales
                        setScaleName( xName, yName, titlex, height, width, g);
                   // x axis
                        drawXasxis( g, width, height,xmargen,ymargen);
                             //y axis
                             drawYasxis( g, xmargen, height,ymargen);
                        //horizontal scale
                             drawXhorizontalScales( g, width, height, scale,xmargen,ymargen);
                             //vertical scale
                             drawYVerticalScales(g, width,height,scale,xmargen,ymargen);
                             //draw x scale no.
                             setXScallNo( g, width, height, scale);
    //                         draw y scale no.
                             setYScallNo( g, width, height, scale);
                             //draw line.
                             drawBar(g,height);
    public void setXScallNo(Graphics g,int width,int height,int scale){
         String s=initialx+"";
         int increment =scaleincr;
         for(int i= xmargen;i<width;i+=scale){
              //G.drawLine(i, height-10, i, height-10);
              g.drawString(s,i,height-2,Graphics.BOTTOM|Graphics.HCENTER);
              s=(initialx+increment)+"";
              increment+=scaleincr;
         return;
    public void setYScallNo(Graphics g,int width,int height,int scale){
         String s=initialy+"";
         int increment =scale;
         for(int i= height-ymargen;i>0;i-=scale){
              //G.drawLine(i, height-10, i, height-10);
              g.drawString(s,0,i,Graphics.TOP|Graphics.LEFT);
              s=(initialy+increment)+"";
              increment+=scale;
         return;
    public void setScaleName(String xName,String yName,int titlex,int height,int width,Graphics g){
         g.setColor(250,250,250);
         g.drawString("X-scale=10",width-70,3,Graphics.TOP|Graphics.RIGHT);
         g.drawString("Y-scale=10",width-10,3,Graphics.TOP|Graphics.RIGHT);
         g.drawString(xName,width/2,(height-fh),Graphics.TOP|Graphics.LEFT);
         int i=0;
         for(int j=0;j<yName.length();j++){
              String s=yName.charAt(j)+"";
         g.drawString(s,1,(height/2)+i,Graphics.TOP|Graphics.LEFT);
         i=i+10;
         return;
    public void drawXasxis(Graphics g,int width,int height,int xmargen,int ymargen){
         g.setColor(0x6FFFFF);
    g.drawLine(xmargen, height-ymargen, width , height-ymargen);
    return;
    public void drawYasxis(Graphics g,int xmargen,int height,int ymargen){
         g.setColor(0x6FFFFF);
         g.drawLine(xmargen,height-ymargen,xmargen,0);
         return;
    public void drawXhorizontalScales(Graphics g,int width,int height,int scale,int xmargen,int ymargen){
         g.setColor(0x6FFFFF);
         int j=0;
         while(j<5){
         for(int i= xmargen;i<width;i+=scale)
              g.drawLine(i, height-(ymargen+j), i, height-ymargen);
         j++;
         return;
    public void drawYVerticalScales(Graphics g,int width,int height,int scale,int xmargen,int ymargen){
         g.setColor(0x6FFFFF);
         int j=0;
         while(j<5){
         for(int i=height-ymargen;i>0;i-=scale){
              g.drawLine(xmargen+j,i,xmargen+j,i);
         j++;
         return;
    public void drawBar(Graphics g,int height){
         int j=1;
         for(int i=index;i<bars.length;i++,j++)
              //g.drawRect(scale+bw*j+pad*j,(height-15)-bars,bw,bars[i]);
              g.drawRect(scale+bw*j+padincr*j,(height-ymargen)-bars[i]-pady,bw,bars[i]);
    g.fillRect(scale+bw*j+padincr*j,(height-ymargen)-bars[i]-pady,bw,bars[i]);
    public void setData(int length)
    public int getData(){
         return 0;
    public void keyPressed(int keyCode) {
    if ((keyCode==KEY_NUM4))
         initialx=initialx+scaleincr;
              if(s1.equals("5 minutes"))
                   if(index==0)
                   index=index+3;
                   else
                   index=index+4;     
              else if(s1.equals("15 minutes"))
                   if(index==0)
                   index=index+1;
                   else
                   index=index+1;
              else
                   index=index+scaleincr;
              repaint();
              System.out.println(scaleincr);
    if ((keyCode==KEY_NUM6))
         if(initialx>0)
              initialx=initialx-scaleincr;
              if(s1.equals("5 minutes"))
                   if(index==3)
                   index=index-3;
                   else
                   index=index-4;     
              else if(s1.equals("15 minutes"))
                   if(index==1)
                   index=index-1;
                   else
                   index=index-1;
              else
                   index=index-scaleincr;
         //index=index-scaleincr;
         repaint();
    if ((keyCode==KEY_NUM2))
         if(initialy>0)
         pady=pady+15;
         initialy=initialy-scale;
         repaint();
    if ((keyCode==KEY_NUM8))
         pady=pady-15;
         initialy=initialy+scale;
         repaint();
    protected void keyReleased(int keyCode)
    protected void keyRepeated(int keyCode)
    Similarly u can do for lines and candle sticks too.
    If u need any help give any mail id to post jad or jar files.
    Regards ,
    Deepika

  • Sb who give me a suggestion about biee's hardware and software

    my system user's count is 1000 and the simultaneous users is 100,which hardware and softwair i can choose
    and when i use bipublisher ,should i pay for it ,if i already buy the biee

    Hard to say based on this info. Try getting stats like request size, data transfer. 10% of your user simultaneous active is very high. The speed of the DWH to which OBIEE is conecting can also be a big issue. Can you provide us with more details?
    Regarding licencing, talk to several local Oracle vendors the might be able to work out a clever deal.
    regards
    John
    http://obiee101.blogspot.com/

  • Difference among graph,char​t and XY graph

    The difference among graph,chart and XY graph
    I am doing a data collection work . And I need to draw a graph or a chart with the data . But I can't make a choice.
    If I draw a real-time graph, which is the best.  And in which situation I use the others.
    Thanks a lot !!!

    They are not a compactly definiendum. as your test station's condition to select.
    draw a real-time graph, I suggest that Chart is OK.  as a data in. it will draw a point out.
    Try to make everything Automatic

  • Excel & ActiveX: Insert arbitrary columns from 2D array and create graph problems

    Hi there,
    I want to insert data from either a 1D or 2D array from LabView into Excel and create graphs.
    I used the information from the following example:
    http://www.ni.com/example/28934/en/
    and was able to create a new Excel file (I'm using Excel 2010), writing data from an 1D array to a column in excel by creating a while loop and using the first element of the array to write it to a specific cell. I use the counter of the loop to write to the next cell when the loop starts over and always delete the first value, which I write to the cell, from the array until it is empty.
    Now I also would like to write a 2D array - so the first column in Excel should be the first column from the array and so. Here I cannot use the loop counter directly as Excel only counts 1,2,... for the rows, but uses A,B,... to count columns. Also I do not know in advance how many columns my 2D array will contain, so creating a lookup table like (A means 1, B means 2,...) is not really an option (except there really is no other way). Is there a possibilty to convert numbers into letters or some way to 'explain' to the program that column 2 in the array means column B in Excel for example, or is there a way to insert new columns?
    I figured out how to add new Worksheets and as I also need to create a certain number of Worksheets and I know that on standard 3 sheets are present when creating the file, I use the 'add' methode to create every new worksheets before worksheet 3 - I could use the same methode to create new columns in Excel, but so far I didn't find a methode to do so. Or is there a way to enter the whole 2D array at once?
    Then I'd like to create a graph (in case of the 1D arrays a bar plot, when using 2D arrays a 3D plot) to view the data. I found this example:
    http://www.ni.com/newsletter/51339/en/
    -> as I do not have the toolkit I'd like to do it using ActiveX directly, so I tried to do things like shown under the headline 'DIY ActiveX/.NET'
    I tried to load the snippet to a new Excel file but got the error message 'microsoft.office.interop.excel.dll not found' and hence the code is not working. That confuses me a little as I would guess when this dll is not present I cannot access Excel from LabView at all, though my understanding of what I'm really doing so far is quiet limited. ;-)
    Also - as far as I understand from the snippet - when creating a new chart object I should be able the create methodes for it, however when I do a right click on the chart object of an ActiveX Worksheet symbol there are none listed.
    To explain my problems better I added a snippet showing my two problems: The inner of the two while loops shows how I import a 1D array. In the outer loop I seperate the columns. I know that currently this is not working as all data end up in column A of the Excel sheet - so I would need to convert the number of the outer counter to A, B,... or find a different solution.
    Moreover on the snippet I placed an ActiveX Worksheet Property with the Chart Object - as I can see the difference to the Chart Object in the example code from the last link above is the color. However I'm not sure what that means and how to change/ solve this.
    And just to make sure - I know this way the VI does not run as the Chart Object is placed completely wrong - I just did it, so it is included in the snippet.
    I'd be thankful for any suggestions,
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    ExcelAreaScan.png ‏60 KB

    Hello everyone and thanks for the answers.
    I only have the LabView Student Edition available here - is the toolkit included in it too. How can I check if it is installed/ available and in case it is installed - where can I find it?
    Today I had time to take a look at the example
    Create via ActiveX Labview a XY Scatter plot graph on an excel sheet
    It almost does what I want in terms of creating a graph. The only problem I could not fix, is that in this example a sheet is created where only the graph is present. i'd like to add the graph to a previously created worksheet. Today I tried get this working but it seems I stilll don't really understand what I'm doing, I'll post a snippet of my code as soon as I can access the PC with LabView on it again.
    I also took a look at the other example for inserting 2D attays - it seems to be what I need, I just had no time so far to test it, I'll post an update when I could test it.
    Thanks for the help so far!

  • Hw can I generate XY graphs directly in a vector data format for printing ie pdf

    A further question re. Printing of Graphs
    There are many similar questions but none where the answers are acceptably adiquite or two or three were the link was broken,
    "Developer exchange forums have been moved" and a pointer to the new
    site, unfort it was hard to find or guess the rest of the link.
    So here is my angle on this problem;
    So far I have tried;
    Using property node: "App.  Printing.Default Printer" to select the printer to use, then
    Using Report Functions to print controls;
    New Report, to generate a new report reference
    Set Report Orientation
    Set Report Margins
    Set Report Font
    Set Report Header Text
    Set Report Font
    Set Report Footer Text
    loop for each page
    Set Report Footer Text,     With page number
    Append Control Image to Report,      several times
    New Report Page
    Until the end of the last page
    Print Report
    Dispose Report
    Initially using existing XY-Graph controls from the front panel.  These
    are on a page of a Tab control to hide these controls while not in use
    and allow them to be hidden while generating the printout. 
    Unfortunately when this page is hidden any graph scales set to
    autoscale don't, (normally don't need to and would otherwise be a waste
    of processor time), resulting in graph plots going off scale or
    becoming a line along the axis.
    An issue is that what is printed appears to be read from the screen, so resolution is much
    lower than required for for printing, resulting in rather pixellated
    printed versions. These prints will usually be emailed, so tried the
    pdf995 "printer driver" but the resulting pdf file size is rather large.
     Currently trying Plot-XY on a much larger picture so as to get
    adequate resolution for printing, however suspect this will result in
    much larger pdf files and probably cause other problems. 
    The preferred solution in this case will probably be to generate print
    output, instead of based on raster images (ie jpg or png), but on a
    vector format, maybe via postscript or directly in pdf format.
    Similar graphs currently printed from Excel via pdf995
    (or OpenOffice) result in files around 20 kb per page. these can be printed at any size
    (at least upto 64 times) without becoming pixellated, so assume these
    are vector based.
    Currently a page with 4 XY Graph controls uses around 40 to 45 kb per
    page but resolution is poor and overcoming that may push file size up
    to 150 to 200 kb per page, and the whole job can be 50 to 100 pages.
    Are there any functions to generate XY graphs directly in a vector data format preferably in pdf or via PostScript format.
    Cheers
    Darryl

    Hi Darryl,
    I was able to reproduce the issue you were seeing, in which a report generation was taking up a large amount of space per page in a PDF utility. I found; however, using my attached VI (notice that it is set to *.png) and the CutePDF utility (free download at http://www.cutepdf.com/) I was able to get a per page size of about 10 KB. Also using the png I found that the image quality seemed to be quite high.
    Please try incorporating this solution into your application and see if it reduces your file sizes.
    Thanks and have a good evening!
    Cheers,
    Jonah
    Applications Engineer
    National Instruments
    Jonah Paul
    Marketing Manager, Embedded Software
    Evaluate the LabVIEW RIO Platform! - ni.com/rioeval
    Attachments:
    print_XY Graph.vi ‏23 KB

  • ADE 2.0 and rendering graphs/figures

    Hello,
    I completed an ePub conversion for a client about a year ago and she is selling her book via Lulu and all of was good with the world. However, she emailed me this morning and tells me that a reader has complained that the graphs and figures are very diffuclt to read when using ADE 2.0. Sure enough, I take a look and they are right!
    Everything looks perfect on the iPad (which is what I intended the book to be read on) BUT Lulu suggestes ADE 2.0 as a way to "read the book immedaitly". I did the print version of the book as well and rasterized the figures using the "export options" dialogue (JPEG at 150dpi, relative to page width) when creating the ePub.
    I experimented with exporting the figures out at 300dpi and in other file formats but  to no avail, can anyone help me?
    Looking forward to hearing from you!

    If you redo the graphs as SVG (and not just SVG with an image tag), that will get you scalability that raster graphics don't provide.  The problem with this suggestion is that while this is easy if you have the source for the graphs especially in Illustrator format, if all you have are the source raster graphics, this will be a lot of work.

  • Problem in Server Admin: cpu and network graphs not updated or empty after lion server update

    Hi!
    Just for archive purpouses because i've already solved that!
    After upgrading from OSX Server 10.7 to 10.7.1 my CPU and Network graphs in Server Admin stop being updated.
    In 24h the graphs where blank (disk usage graph seem to keep working).
    First i read about "what is the application responsible for this"; it's called ServerPerfLog, and you can see if it's running that way:
         # ps ax | grep ServerPerf
    If you don't see anything else than your own "grep", that means that no application is running, no data is being collected.
         41324 s000  R+     0:00.00 grep ServerPerf
    A positive response for this (meaning that the service is running) should be something like that (2 lines: your grep and the service app itself):
         94   ??  Ss     0:04.71 /usr/libexec/ServerPerfLog
         41344 s000  R+     0:00.00 grep ServerPerf
    Later i read about "where is the config file for this service app", and you can find it here:
         /System/Library/LaunchDaemons/com.apple.ServerPerfLog.plist
    If you edit this config file, check that the "Key > Disabled" is set to "False"
         # vi /System/Library/LaunchDaemons/com.apple.ServerPerfLog.plist
            <key>Disabled</key>
            <false/>
    After that, i try to launch the service that updates this graphs again, by hand, performing the following command:
         # sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.ServerPerfLog.plist
    And the service got launch!!! yeeeepa!! i see a first update in graph data.
    Also the "ps" query reply that the service was running!!
    The bad things came a day after, when i saw that the graphs stop again....
    I check if the service was running executing again the "ps" command, and that show me that the service was stopped again; no ServerPerfLog process was running.
    But r e l a x, because the process hang because of a permissions problem.
    You should know, I run "Repair permissions" within "Disk Utilities" over the running system disk, eeee... voila!
    I hope that helps someone to get his fancy graphs back!
    Regards,
    t

    You are God like!!! Wooo hooo! Thanks bud!

  • How do i  create a line graph and scatterplots graph in numbers?

    hi fellow mac users, i am taking a biology class and i have to create a graph, the only problem is i dont know where to begin. I would love your advice and ideas on how to do so.THE OTHER TYPES OF GRAPHS THAT I HAVE TO MAKE IS A LINE GRAPH     SCATTER PLOT    BAR GRAPH   AND    A  PIE CHART.  if yall could help me that would be great. (a list of steps will help me alot)

    HI izzie,
    As well as the link in Wayne's post, you can get the Numbers '09 User Guide through the Help menu in Numbers.
    Besides Chapter 7, which deals with your current question, I would strongly suggest reading at least the first four chapters of the guide for a good grounding in the basics of using Numbers.
    Regards,
    Barry

  • Read data from XML file and plot graph on Ms Words

    Hi,
    I'm using Visual Studio 2010, what I want to do is written in the title.
    so far i was able read and plot graph on a Form but i unable to use the same method on Crystal Reporting.
    The method plotting in Crystal Reporting is complicated and it require a fix data set or database which is not suitable for my case because every time the number of column and row or data will be different. (this is what i think base on what i found)
    is there a way for me to display the output on a ms words?
    and what is the method.
    thanks.

    Hi Huangcongmazhananzi,
    Based on your description, I’m afraid that it is not the correct forum for this issue, since this forum is to discuss the VS IDE.
    I might not have the correct detailed answer you need, but I might lead you into the right direction to solve your problem.
    If this issue is related to the Windows Forum app, this forum would be better:
    http://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms
    But if it is related to the Crystal Reporting, you could post the issue here:
    http://forums.sdn.sap.com/forum.jspa?forumID=313&start=0
    is there a way for me to display the output on a ms words?
    If it is related to the Office, maybe you could select the correct forum here:
    http://social.msdn.microsoft.com/Forums/office/en-US/home?category=officedev
    Best Regard,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Finding cycles in an undirected graph.

    I've been trying to implement my own graph class, and one of the things I would like to do is do a DFS to find cycles.
    So far I've been able to write this and I'm pretty confident it works:
         static boolean findCycle(){
              LinkedList<Node> queue = new LinkedList<Node>();
              unEnqueue();
              Node start = graph.getFirst();
              start.visited = true;
              queue.push(start);
              Node previous = new Node();
              previous = start;
              while (!queue.isEmpty()) {
                   Node node = queue.pop();
                   node.visited = true;
                   System.out.println("previous is "  +previous);
                   for (Node neighbor : node.neighbours) {
                        if(!neighbor.visited){
                             queue.push(neighbor);
                        }else if(allVisited()){
                             return true;
                        }else if (neighbor.visited && neighbor == start){
                             unVisit();
                        }else if(neighbor.visited && neighbor != previous){
                             System.out.println("neighbor is "+ neighbor);
                             return true;
                   previous = node;
                   System.out.println("previous is " +previous);
              return false;
         }Visited is just a boolean value each node has.
    unVisit takes our graph and resets all visited values to false.
    After this returns I check each node and list those that are visited - these nodes constitute my cycle.
    This returns the nodes out of order (not in the order they are listed) which is fine.
    It also breaks if there is no cycle in the graph.
    Can anyone think of how to correctly return false? Or, maybe a graph that would break this?
    Thanks

    Thanks for the reply. I've found some inputs where my algorithm doesn't work so I suppose I should back up and ask a new question:
    Is it possible to do a DFS iteratively like I am, find the path of nodes that represents a cycle and then return that? The main problem I run into when doing these sorts of things is that since the graph is undirected the DFS likes to yield cycles of the first two nodes that are connected. Another issue is that since I only have the nodes and their neighbors there really aren't edges to iterate through and mark as back, cross etc. Is it possible to use a hashmap to store the path?
    Let me know if I need to clarify things further
    Also: I didn't return a cycle before because the cycle was represented as all nodes that had their boolean visited set to true. I could print the list simply by iterating through the graph and printing which nodes had a true visited boolean.
    Edited by: Blitzkev on May 17, 2010 6:24 PM
    Edited by: Blitzkev on May 17, 2010 6:27 PM
    static LinkedList<Node> findCycle(LinkedList<Node> g){
              Stack<Node> s = new Stack<Node>();
              HashMap<Node,Node> hm = new HashMap<Node,Node>();
              LinkedList<Node> cycle = new LinkedList<Node>();
              boolean done = false;
              unMark(g);
              unVisit(g);
              s.push(g.getFirst());
              Node currNode = null;
              while (!s.isEmpty() && !done) {
                   currNode = s.pop();
                   currNode.visited = true;
                   for (Node neighbor : currNode.neighbours) {
                        if( !neighbor.visited && neighbor.marked == 1 ) {
                             hm.put(neighbor, currNode);
                             Node n = neighbor;
                             do {
                                  cycle.add(n);
                             } while( (n = hm.get(n)) != neighbor && !cycle.contains(n) && n != null );
                             done = true;
                             break;
                        if( !neighbor.visited ) {
                             s.push(neighbor);
                             neighbor.marked = 1;
                        hm.put(neighbor, currNode);
              return cycle;
         }I got it working with a hashmap.
    Edited by: Blitzkev on May 17, 2010 6:48 PM

  • Searching bridge in undirected graph

    Hi,
    we have a homework to school to find a bridge in undirected graph.
    We got input:
    8 - number of nodes
    0 3 - node 0 is connected with node 3
    1 3
    2 3
    4 5
    4 6
    4 7
    3 4
    0 1
    1 2
    5 6
    6 7
    0 0 - end of input
    Here is a correct output for this graph:
    3 4 - edge from node 3 to node 4 is a bridge
    0 0 - end of output
    Here is my code which work perfectly for any graphs i think about but when i tried to commit it to our evaluating system it fails in 5 cases from 10. System says that it fails on diamond graph without needlepoint. I think I must have something wrong when i go throught graph (some condition or something). I tried to implement algorithm described here [http://www.cs.ucr.edu/~neal/2005/cs141/wiki/index.cgi?Cs141_Home/Lecture10] So if you know whats wrong or you have some idea please help.:)
    package pal;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    class Node{
    enum NodeState {
    White, Gray, Black
    NodeState state = NodeState.White;
    int id = 0;
    int hm = 0;
    int zm = 0;
    int from = -1;
    boolean root = false;
    ArrayList<Node> children = new ArrayList<Node>();
    public int min(int hm, int zm){
    int min;
    if(hm < zm){
    min = hm;
    return min;}
    else{
    min = zm;
    return min;
    public void tree(){
    if(state == NodeState.White){
    state = NodeState.Gray;
    for (int i = 0; i < children.size(); i ){
    if (children.get(i).state == NodeState.Black){ continue;}
    else if (children.get(i).state == NodeState.Gray && children.get(i).id == from){continue;}
    else if(children.get(i).state == NodeState.Gray && children.get(i).id != from){
    zm = min(children.get(i).hm,zm);
    continue;
    else{
    children.get(i).from = id;
    children.get(i).hm = hm  +1;+
    +children.get(i).zm = children.get(i).hm;+
    +children.get(i).tree();}+
    +}+
    +if(state != NodeState.Black && root){+
    +state = NodeState.Black;+
    +}+
    +else if(!root && state != NodeState.Black){+
    +state = NodeState.Black;+
    +for (int i = 0; i< children.size();i ++){
    if(children.get(i).id == from){
    children.get(i).zm = min(children.get(i).zm, zm);
    children.get(i).tree();
    public class Main {
    public static void main(String[] args) throws IOException {
    Node n;
    int node1, node2;
    int non;
    ArrayList<Node> nodeList = new ArrayList<Node>();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    non = Integer.parseInt(br.readLine());
    for(int i = 0; i < non; i++){
    n = new Node();
    n.id = i;
    if(i==0){
    n.root = true;
    nodeList.add(n);
    while(true){
    StringTokenizer st = new StringTokenizer(br.readLine());
    node1 = Integer.parseInt(st.nextToken());
    node2 = Integer.parseInt(st.nextToken());
    if( (node1+node2) == 0) break;
    nodeList.get(node1).children.add(nodeList.get(node2));
    nodeList.get(node2).children.add(nodeList.get(node1));
    /*for(int i = 0; i < non ; i++){*
    *nodeList.get(i).tree();*
    nodeList.get(0).tree();
    // System.out.println("--------------");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < non; i++){
    if((nodeList.get(i).zm == nodeList.get(i).hm)&& !nodeList.get(i).root){
    sb.append(nodeList.get(i).from);
    sb.append(" ");
    sb.append(nodeList.get(i).id);
    sb.append("\n");
    sb.append("0 0");
    System.out.println(sb);

    xtem wrote:
    Hi,
    we have a homework to school to find a bridge in undirected graph.
    We got input:
    8 - number of nodes
    0 3 - node 0 is connected with node 3
    1 3
    2 3
    4 5
    4 6
    4 7
    3 4
    0 1
    1 2
    5 6
    6 7
    0 0 - end of input
    Here is a correct output for this graph:
    3 4 - edge from node 3 to node 4 is a bridge
    0 0 - end of output
    Here is my code which work perfectly for any graphs i think about but when i tried to commit it to our evaluating system it fails in 5 cases from 10. System says that it fails on diamond graph without needlepoint. I think I must have something wrong when i go throught graph (some condition or something). I tried to implement algorithm described here [http://www.cabletrain.com] So if you know whats wrong or you have some idea please help.:)
    package pal;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    class Node{
    enum NodeState {
    White, Gray, Black
    NodeState state = NodeState.White;
    int id = 0;
    int hm = 0;
    int zm = 0;
    int from = -1;
    boolean root = false;
    ArrayList<Node> children = new ArrayList<Node>();
    public int min(int hm, int zm){
    int min;
    if(hm < zm){
    min = hm;
    return min;}
    else{
    min = zm;
    return min;
    public void tree(){
    if(state == NodeState.White){
    state = NodeState.Gray;
    for (int i = 0; i < children.size(); i ){
    if (children.get(i).state == NodeState.Black){ continue;}
    else if (children.get(i).state == NodeState.Gray && children.get(i).id == from){continue;}
    else if(children.get(i).state == NodeState.Gray && children.get(i).id != from){
    zm = min(children.get(i).hm,zm);
    continue;
    else{
    children.get(i).from = id;
    children.get(i).hm = hm  +1;+
    +children.get(i).zm = children.get(i).hm;+
    +children.get(i).tree();}+
    +}+
    +if(state != NodeState.Black && root){+
    +state = NodeState.Black;+
    +}+
    +else if(!root && state != NodeState.Black){+
    +state = NodeState.Black;+
    +for (int i = 0; i< children.size();i ++){
    if(children.get(i).id == from){
    children.get(i).zm = min(children.get(i).zm, zm);
    children.get(i).tree();
    public class Main {
    public static void main(String[] args) throws IOException {
    Node n;
    int node1, node2;
    int non;
    ArrayList<Node> nodeList = new ArrayList<Node>();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    non = Integer.parseInt(br.readLine());
    for(int i = 0; i < non; i++){
    n = new Node();
    n.id = i;
    if(i==0){
    n.root = true;
    nodeList.add(n);
    while(true){
    StringTokenizer st = new StringTokenizer(br.readLine());
    node1 = Integer.parseInt(st.nextToken());
    node2 = Integer.parseInt(st.nextToken());
    if( (node1+node2) == 0) break;
    nodeList.get(node1).children.add(nodeList.get(node2));
    nodeList.get(node2).children.add(nodeList.get(node1));
    /*for(int i = 0; i < non ; i++){*
    *nodeList.get(i).tree();*
    nodeList.get(0).tree();
    // System.out.println("--------------");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < non; i++){
    if((nodeList.get(i).zm == nodeList.get(i).hm)&& !nodeList.get(i).root){
    sb.append(nodeList.get(i).from);
    sb.append(" ");
    sb.append(nodeList.get(i).id);
    sb.append("\n");
    sb.append("0 0");
    System.out.println(sb);

  • ADF Faces and BI Graph?

    Is it possible to use BI Graph with ADF Faces?
    So far I was using BC4J/JSP/Struts and to put Graph (<graph:Graph/>) into JSP page was easy - using Data Control Palette. Now I want to migrate to JSF (ADF Faces) but when I create JSF JSP - it is impossible to insert some ViewObject as Graph from Data Control Palette.
    Thanks for any clue.
    brano

    My current solution is:
    The ADF Faces main page:
    <af:showOneTab position="above">
    <af:showDetailItem text="Graph Include" disclosed="true">
    <f:verbatim>
    <jsp:include page="${pageContext.request.contextPath}/graphs/Graph.jspx"
    </f:verbatim>
    </af:showDetailItem>
    The Graph page:
    <?xml version='1.0' encoding='windows-1252'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
    xmlns:graph="/webapp/graph.tld"
    xmlns:adf="http://xmlns.oracle.com/adf/ui/jsp/adftags">
    <jsp:output omit-xml-declaration="true"
    doctype-root-element="HTML"
    doctype-system="http://www.w3.org/TR/html4/loose.dtd"
    doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
    <jsp:directive.page contentType="text/html;charset=windows-1252"/>
    <html>
    <adf:pagedefinition/>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=windows-1252"/>
    <title>Graph</title>
    </head>
    <body><graph:Graph data="${bindings.EmployeesView1}"
    imageHeight="240" imageWidth="320"/>
    </body>
    </html>
    </jsp:root>
    When I try to run this, I get the following error:
    500 Internal Server Error
    javax.servlet.jsp.JspException: data attribute evaluates to null
         at oracle.jbo.html.jsp.graph.GraphTag.doStartTag(GraphTag.java:212)
         at graphs.Graph_jspx._jspService(_Graph_jspx.java:67)
         [graphs/Graph.jspx]
    Could you please post the solution?

  • How do I write a vi that will save graph data and text data (related to the graph) so the next time I want to view the graph data the text data is included in the read vi?

    I am new at writing vi's and hope you may be able to help. I would like to create a vi that will graph measurements taken from a daq device. I would like to include text data that a user can choose from (example: machine number, test circuit, load cell type) that will stay with the graph so when the graph is viewed at a later time the text data (explaining parts of the graph) will display with the graph data. I have included a vi I am using to capture and display a force value. Any help would be greatly appreicated.
    Attachments:
    force.vi ‏500 KB

    What you want is a DATALOG file:
    When you save a file, use the BUNDLE function to bundle your machine number, test circuit, whatever (include a few spare fields), plus your graph data. Get the graph data from the source, or use a local variable of the graph itself.
    Wire the bundle output to the DATALOG TYPE of a NEW FILE function. (I presume you'll use a FILE DIALOG set to SAVE FILE to choose a file path).
    Write the same bundle output to the DATA input of a WRITE FILE function.
    Use a CLOSE FILE function to (ahem) close the file.
    When you want to read a file, use a FILE DIALOG set to EXISTING FILE (or some other means) to specify what file to read. Wire the same cluster type to the DATALOG TYPE of the FILE DIALOG, so that it will only
    offer files of the correct type.
    When you have a file path chosen, wire the bundle to the DATALOG TYPE input of a FILE OPEN operation.
    Use a FILE READ to read a single cluster - the output of FILE READ will be a cluster of the right type.
    Use a CLOSE FILE function to....
    Out of the FILE READ function, you can UNBUNDLE BY NAME the data and send to the graph and the other fields, or, if you're clever, you can use a cluster on the screen, and not unbundle it. That's harder though, since you probably want the text fields to be controls (inputs) and the graph to be an indicator (output).
    Hope that helps.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

Maybe you are looking for

  • Ipod replaced 3x -- could it be the computer?

    The same thing has happened to my 20G clickwheel 3 times. First songs skip when they are playing, then Ipod freezes, I try resetting and then the folder wth ! pops up, can't turn it back on. My friend hooked up to my computer, and the same happened t

  • Nokia E73 Mode File Manager/Gallery Alternatives?

    Not sure if I'm in the right section, but I'm assuming. For the Nokia E73 Mode the Gallery is too chaotic and disorganized. The images are organized on "Date Taken" instead of alphabetical or folders. Normally I resolve this issue by viewing images v

  • OATS - 12.1.0.1.0361 Issue with running a  scenario

    Hi, I am doing a comparison of Hits/sec and cpu usage for a scenario with OATS and LR. I have remote load generator and app server. With OATS, i am getting almost half the hits/sec and cpu as compared to lr. Till now what i have noticed is that the t

  • Attachement linked to purchase order

    I want to know where the attachements linked to purchase order are getting stored in SAP.Since the attachement are linked to purchase order(header level) ,is it possible to link those attachements at item level so when we select a particular item  an

  • All cd's are seen as blank cd's

    I'm not exactly sure what the issue is and every time new information is discovered, it gets even weirder. So I put in a blank cd. pcmanfm shows a blank cd. So far so good. I burn a cd and it's successful. The cd ejects and I put it back in to test i