Simplify Algorithm

Hello,
I am trying to develop an algoithm to store all the top left hand co-ordinates of each square on a snakes and ladders board like so.
The first line goes from left to right then up one then right to left etc.. like so.
22 23 24 etc....
21................................. 12 11
0 1 2 3 4 5 6 7 8 9 10
The algorithm that i have come up with to store the x coord of each square is.
660 * (i/12%2)) + (i/12%2 * -2 + 1) * i%12 * 60
i represents the number of each square from 0 to 71.
How can I simplify this algorithm to get rid of the duplicate sums,
e.g. i/12%2
Thanks
Andrew

How can I simplify this algorithm to get rid of the
duplicate sums,
e.g. i/12%2use mulitple lines and intermediate values
int foo = i/12%2;
660*foo + (foo-1)*i%12*60
but even better is to not use math to implement conditionals, and to document your magic numbers, for example:
int colCount = 12;
int rowNum = i/colCount;
int colNum = i%colCount; // assumes numbers run left to right..
// but odd rows run backwards
if((rowNum & 1) == 1) colNum = colCount - colNum -1;
then you can convert numbers into screen coordinates
xValue = xMargin + colNum*cellWidth;
one step at a time is better than a bunch o' math all stuffed onto one line.

Similar Messages

  • Do these two tools use the same algorithm?

    Do Oracle In-Memory Database(TimesTen) and Oracle Coherence use the same algorithm?
    Both of them are in-memory databases?
    If not, what is the difference?
    Edited by: qck on Aug 11, 2009 8:17 PM

    No, they are different tools and they use different algorithm.
    Oracle TimesTen In-Memory Database is a memory-resident relational database. Deployed in the application tier as an
    embedded database, Oracle TimesTen In-Memory Database operates on databases that fit entirely in physical memory using standard SQL interfaces.
    Oracle TimesTen In-Memory
    Database libraries are also embedded within applications, eliminating context switching and unnecessary network operations, further improving performance.
    Oracle TimesTen In-Memory Database (TimesTen) is designed with the knowledge that data resides in main memory and can take more direct routes to
    data, reducing the length of the code path and simplifying algorithms and structure.
    Oracle Coherence is a JCache-compliant in-memory distributed data grid solution for clustered applications and application servers. Organizations can predictably scale mission-critical applications by using Oracle Coherence to provide fast and reliable access to frequently used data. Oracle Coherence enables customers to push data closer to the application for faster access and greater resource utilization. By automatically and dynamically partitioning data in memory across multiple servers, Oracle Coherence enables continuous data availability and transactional integrity, even in the event of a server failure. Oracle Coherence is a shared infrastructure that combines data locality with local processing power to perform real-time data analysis, in-memory grid computations, and parallel transaction and event processing.
    In my opinion, Oracle Coherence is more powerful. It mostly co-located on multiple server's memories. It is not only for databases (by integrating with The Hibernate or TopLink) but also for other applications.
    Edited by: jetq on Aug 11, 2009 11:20 PM

  • LR3 "Extra Processing in Develop" Performance Problem

    I have been investigating a specific LR3 performance problem.  It may explain a small subset of the problems people have reported in the "Why is LR3 So Slow?" thread.   I'm starting this thread to focus on this particular problem.  I hope others will confirm/refute/refine my findings.
    The Problem
    In Develop, when I make an adjustment, normally the following happens: The CPU usage (as shown in Activity Monitor's bar graph) jumps to between 50 and 75% for all four cores, the updated image appears, and the CPU usage settles back down.  This all happens in less than half a second.  Note: this is with the image at the Fit size.  However, sometimes I instead get the following after an adjustment: the CPU usage jumps to 50 to 75% for all four cores and the updated image appears as usual, however, instead of settling back down, the CPU usage jumps up to 90 to 100% for all cores and stays there for 3 to 5 seconds before settling down. Thus it appears that LR is doing some kind of "extra processing" since a lot of computation is happening AFTER the updated image has already appeared.  I will refer to this problem as "EP".  Obviously, when you are getting EP, editing in Develop becomes very balky.
    Dependency on ratio between image size and displayed size
    It appears that EP only happens when the displayed size of the image (in Fit zoom level and perhaps also Fill zoom level) is above a certain percentage of the actual image size (as currently cropped).  Evidence: When editing full 21MP 5D2 images, I don't experience EP.  If I crop the 5D2 image fairly significantly, then I can get EP.  When editing 10MP images from my Canon S90, I usually get EP for landscape orientation pictures but not for portrait orientation pictures (since in Fit mode, landscape images display at a higher zoom level than portrait images).  If I am getting EP, I can eliminate it by sufficiently reducing the size that LR is displaying the image by resizing the LR window smaller, opening additional panels (I normally edit with only the right panel open), displaying the toolbar, etc.  It appears that EP is enabled when the displayed image is about 50% or larger w.r.t. the actual image (as currently cropped).  For example, EP becomes enabled when a 3648 pixel wide S90 image is displayed at least 17 and 7/8 inches wide on my 100 ppi monitor (i.e. about 1787 pixels).
    Dependency on HOW an adjustment is invoked
    Even when the displayed image size is large enough w.r.t. the actual image size to enable EP, whether you get it on a given adjustment depends on how you invoke it:
    - If you CLICK (i.e. press the mouse button down and quickly release it) on the track of one of the sliders (a technique I use often to make big jumps), EP will happen.
    - If you press the mouse button down on a slider handle, drag it to a new position, and quickly release the mouse button), EP will happen
    - If you press the mouse button down on a slider handle, drag it to a new position, but continue to hold the mouse button down until the displayed image is updated, EP does NOT happen (either before or after you then release the mouse button).
    - If you highlight the numeric field at the end of a slider and use the arrow keys (possibly along with Shift) to increment or decrement the value, EP does NOT happen.
    - EP will happen if you resize the LR window such that the displayed image size is above the threshold.  (In fact, I determined the threshold by making a series of window width increases until I saw EP indicated by the CPU bar graphs.)
    - EP can happen with local adjustment brush applications, but as with the sliders, it depends on HOW you perform the brush stroke.  Single click and drags with immediate mouse release cause EP, drags with delayed mouse button release don't.
    - Clicking an earlier History state causes EP
    - More exploration could be done.  For example, I haven't looked at Graduated Filter and Spot Removal adjustments.
    My theory of what's happening
    With LR2, my understanding is that in Develop mode when the displayed image is below 1:1 zoom level, after an adjustment is invoked, LR calculates the new version of the image to display using a fast, simplified algorithm that doesn't include the more computationally intensive adjustments like Sharpening and Noise Reduction (and perhaps works on a lower rez version of the image with multiple sensels binned together?).  It appears that in conditions described above, LR3 calculates the initial, fast image update and then goes on to do the full update of the image, including the computationally intensive adjustments.  Evidence:   setting Sharpening Amount and Luminance and Color Noise Reduction to zero eliminates EP (or reduces the amount of time it takes to be barely noticeable).  I'm not sure whether the displayed image is updated with the results of the extra processing.  I think the answer is Yes since when I tried an adjustment of changing Sharpening Amount from 0 to 90, the initial update of the displayed image showed sharpening but after the EP, the displayed image was updated again to show somewhat different sharpening. Perhaps Adobe felt that it would be useful to see the more accurate version of the image when it is at or above 50% zoom.  Maybe the UI is supposed to cancel the EP if you start to make another adjustment before it has completed but the canceling doesn't happen unless you invoke the adjustment in one of the ways described above that doesn't cause EP.  
    Misc
    - EP doesn't seem to happen for Process 2003
    - As others have mentioned, I'm surprised that LR (both version 2 and 3) in 64bit mode doesn't use more available RAM.  I don't think I've seen LR go above 4GB of virtual memory or above 3GB "Real Memory" (as reported by Activity Monitor) even though I have several GB free.
    - It should be obvious from the above that if you experience EP, there are workarounds: reduce the size of the displayed image (e.g. by window resizing), invoke adjustments in ways that don't cause EP, turn off Sharpening and Noise Reduction until the end of editing an image.
    System specs
    First generation Intel Mac Pro with two dual-core CPUs at 2.66 Ghz
    OS 10.5.8
    21GB RAM
    ACR cache on volume striped across 3 internal SATA drives
    LR catalog and RAWs on an internal SATA drive
    30" HP LP3065 monitor (2560 pixels wide)
    NVIDIA GeForce 7300 GT

    I'm impressed by your thorough analysis.
    Clearly, the programmers haven't figured out the best way to do intelligent caching and/or parallel rendering at a reduced size yet.
    In my experience reducing the settings in the "Details" panel doesn't help.
    What really bugs me is that the lag (or increasing lack of interactiveness) depends on the number of adjustments one has made.
    This shouldn't be the case. If a cache is produced then every further adjustment should only cost the effort for that latest adjustment and not include adjustments before it. There are things that stand in the way of straightforward edit applications:
    If you work below 1:1 preview, adjustments have to be shown in a reduced form. If you don't have a way to faithfully mimic the adjustments on the reduced size, you have to do them on the original image and then scale down. That's expensive.
    To the best of my knowledge LR uses a fixed image pipeline. Hence, independently of the order in which you apply edits, they are always performed in the same fixed order. Say all spot removal operations are done first. If you have a lot of adjustment brush edits and then add a spot removal operation, it means that all the adjustment brush operations have to be replayed each time you do a little adjustment on your spot removal edit.
    I believe what you are seeing is mostly related to 1.
    I also believe that the way LR currently handles a moderate number of edits is unacceptable and incompatible with the notion that it is usable in a commercial setting for more than trivial edits. I suspect there is something else going on. If everyone saw the deterioration in performance after a number of edits that I see, I don't think LR would be as accepted as it is. Having said that, I've read that the problem of repeated applications of the adjustment brush slowing LR down has existed for a long time. I truly hope that this doesn't mean we'll have to live for it for the foreseeable future.
    There are two ways I can see how 2. should be addressed:
    combine the effects of a set of operations into one bitmap operation. Instead of replaying all adjustment brush strokes one after the other (speedwise it feels like this is happening), compute a single bitmap operation that combines all effects.
    give up the idea that there is an image pipeline with a fixed execution order.
    Some might argue that the second point is at odds with the whole idea of parametric editing, but I dispute that. Either edit operations are commutable in which case the order is immaterial, or they are not. If they are not, the user applies the edits in a way as he/she sees fit and will thus compensate for any effect of a changed ordering.
    N.B., currently the doctrine of "fixed ordering of edit applications" results in the effect that even if you convert an image into B&W all your adjustment brush edits that applied colour tints will still show through. Reasoning: The user should be able to locally tint a B&W image. I agree with the latter but this could be achieved by only applying those tinting brush strokes that were created after the B&W conversion. All the ones that happened before should only be used to obtain the correct luminance values for the B&W conversion but obviously they shouldn't cause tinted areas.
    The above example demonstrates to me that users naturally expect operations to occurr in the order they have been introduced, not in a fixed predefined order. If that principle were followed, I see no reason why the speed of a single edit should depend on the number of edits that were done to the image before.
    I hope the programmers can (and the management wants to) address the performance issues. While I find LR usable for pretty modest edits, in no way the performance on my system approaches that would I would expect from an industrial strenght application.
    P.S.: Your message reminded me of the following: When I experience serious lag with LR showing the strokes I make with an adjustment brush, it helps to pause a moment after the first click before one starts moving. This allows LR to catch up and then one can see the effect of the application pretty much interactively. Otherwise, there is terrible lag and the feedback where you have brushed an effect comes way too late.

  • Call library function node with array of clusters using array data pointer

    Hello all.
    I am writing a LabVIEW wrapper for an existing DLL function.
    The function has, as one of its parameters, an array of structs.  The struct is very simple, containing two integers.  I am using the call library function node to access it.
    In Labview I created an array of clusters, where the cluster has two 32-bit integers as its members.  So far, so good.
    Now I have to pass this in to the Call Library Function Node.  Here I am running into trouble.
    I have used The topic in LAVA and The topic in the knowledge base as my primary sources of information, though I have read a bunch of forum topics on the subject too.
    I do understand that I could write a new function which takes as a parameter a struct with the size as the first member and an array as the second, and I might just do this and have it call the regular function, but I was hoping to do it more simply.
    According to the C file which LabVIEW generates for me from the CLFN when I choose "Adapt to Type" and "Array Data Pointer", the prototype it is expecting is:
    int32_t myFunc(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, void data[], int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    And the prototype of the function in my DLL is
    int borland_dll myFunc(DWORD handle, usint channel,
    int FIFOnumber, struct mStruct *data, int numWords, int *actualLoaded, int *actualStartIndex);
    This looks like a match to me, but it doesn't work (I get garbage in data).  From the topic in LAVA referenced above, I understood that it would work.  It does not.
    If I cast data to the pointer-to-pointer I get when I generate c code by wiring my struct to a CIN and generating, then I seem to get what I expect. But this seems to work when I choose "pointers to handles" too, and I would expect array data pointer to give a different result.
    Is there any way to get this to work directly, or will I have to create a wrapper?  (I am currently using LabVIEW 2011, but we have customers using 2009 and 2012, if not other versions as well).
    Thank you.
    Batya
    Solved!
    Go to Solution.

    OK, here is more detailed information.
    I have attached the VI.
    This is the code from the  "C" file created by right-clicking the CLN and creating a "C" file. 
    When the parameter in the CLN is set to "array data pointer":
    /* Call Library source file */
    #include "extcode.h"
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, void data[], int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, void data[], int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex)
    /* Insert code here */
     When the parameter is "pointers to handles":
    /* Call Library source file */
    #include "extcode.h"
    /* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
    #include "lv_prolog.h"
    /* Typedefs */
    typedef struct {
    int32_t control;
    int32_t data;
    } TD2;
    typedef struct {
    int32_t dimSize;
    TD2 data[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    #include "lv_epilog.h"
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex)
    /* Insert code here */
     When the parameter is set to "handles by value":
    /* Call Library source file */
    #include "extcode.h"
    /* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
    #include "lv_prolog.h"
    /* Typedefs */
    typedef struct {
    int32_t control;
    int32_t data;
    } TD2;
    typedef struct {
    int32_t dimSize;
    TD2 data[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    #include "lv_epilog.h"
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex)
    /* Insert code here */
    As to the DLL function, it is a bit more complicated than I explained above, in the current case.  My VI calls the function by this name in one DLL, and that DLL loads a DLL and calls a function (with the same name) in the second DLL, which does the work. (Thanks Rolfk, for helping me with that one some time back!)
    Here is the code in the first ("dispatcher") DLL:
    int borland_dll Load_Transmit_FIFO_RTx(DWORD handle, usint channel, int FIFOnumber, struct FIFO_DATA_CONTROL *data, int numWords, int *actualLoaded, int *actualStartIndex)
    t_DispatchTable *pDispatchTable = (t_DispatchTable *) handle;
    int retStat = 0;
    retStat = mCheckDispatchTable(pDispatchTable);
    if (retStat < 0)
    return retStat;
    if (pDispatchTable->pLoad_Transmit_FIFO_RTx == NULL)
    return edispatchercantfindfunction;
    return pDispatchTable->pLoad_Transmit_FIFO_RTx(pDispatchT​able->handlertx, channel, FIFOnumber, data, numWords, actualLoaded, actualStartIndex);
    borland_dll is just "__declspec(dllexport)"
    The current code in the DLL that does the work is:
    // TEMP
    typedef struct {
    int control;
    int data;
    } TD2;
    typedef struct {
    int dimSize;
    TD2 data[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    // END TEMP
    int borland_dll Load_Transmit_FIFO_RTx(int handlertx, usint channel, int FIFOnumber, struct FIFO_DATA_CONTROL *data, int numWords, int *actualLoaded, int *actualStartIndex){
    struct TRANSMIT_FIFO *ptxFIFO; //pointer to transmit FIFO structure
    usint *pFIFOlist; //pointer to array of FIFO pointers to FIFO structures
    int FIFOentry, numLoaded;
    usint *lclData;
    usint nextEntryToTransmit;
    // TEMP
    FILE *pFile;
    int i;
    TD1** ppTD = (TD1**) data;
    TD1 *pTD = *ppTD;
    pFile = fopen("LoadFIFOLog.txt", "w");
    fprintf(pFile, "Starting Load FIFO with %d data words, data pointer 0x%x, with the following data&colon; \n", numWords, data);
    for (i = 0; i < numWords; i++) {
    fprintf(pFile, "%d: control--0x%x, data--0x%x \n", i, data[i].control, data[i].data);
    fflush(pFile);
    fprintf(pFile, "OK, using CIN generated structures: dimSize %d, with the following data&colon; \n", pTD->dimSize);
    for (i = 0; i < numWords; i++) {
    fprintf(pFile, "%d: control--0x%x, data--0x%x \n", i, pTD->data[i].control, pTD->data[i].data);
    fflush(pFile);
    // END TEMP
    if ((handlertx) <0 || (handlertx >= NUMCARDS)) return ebadhandle;
    if (cardrtx[handlertx].allocated != 1) return ebadhandle;
    pFIFOlist = (usint *) (cardrtx[handlertx].segaddr + cardrtx[handlertx].glob->dpchn[channel].tr_stk_ptr​);
    pFIFOlist += FIFOnumber;
    ptxFIFO = (struct TRANSMIT_FIFO *)(cardrtx[handlertx].segaddr + *pFIFOlist);
    //use local copy of ptxFIFO->nextEntryToTransmit to simplify algorithm
    nextEntryToTransmit = ptxFIFO->nextEntryToTransmit;
    //on entering this routine nextEntryToLoad is set to the entry following the last entry loaded
    //this is what we need to load now unless it's at the end of the FIFO in which case we need to wrap around
    if ( ptxFIFO->nextEntryToLoad >= ptxFIFO->numEntries)
    *actualStartIndex = 0;
    else
    *actualStartIndex = ptxFIFO->nextEntryToLoad;
    //if nextEntryToLoad points to the last entry in the FIFO and nextEntryToTransmit points to the first, the FIFO is full
    //also if nextEntryToLoad == nextEntryToTransmit the FIFO is full and we exit without loading anything
    if (( (( ptxFIFO->nextEntryToLoad >= ptxFIFO->numEntries) && (nextEntryToTransmit == 0)) ||
    ( ptxFIFO->nextEntryToLoad == nextEntryToTransmit)) && (ptxFIFO->nextEntryToLoad != INITIAL_ENTRY)){
    *actualLoaded = 0; //FIFO is full already, we can't add anything
    return 0; //this is not a failure, we just have nothing to do, this is indicated in actualLoaded
    numLoaded = 0;
    lclData = (usint *)data; //must use 16 bit writes to the module
    //conditions are dealt with inside the for loop rather than in the for statement itself
    for (FIFOentry = *actualStartIndex; ; FIFOentry++) {
    //if we reached the end of the FIFO
    //if the module is about to transmit the first element of the FIFO, the FIFO is full and we're done
    //OR if the module is about to transmit the element we're about to fill in, we're done - the
    //exception is if this is the first element we're filling in which means the FIFO is empty
    if ((( FIFOentry >= ptxFIFO->numEntries) && (nextEntryToTransmit == 0)) ||
    ((FIFOentry == nextEntryToTransmit) && (FIFOentry != *actualStartIndex) )){
    *actualLoaded = numLoaded;
    //set nextEntryToLoad to the end of the FIFO, we'll set it to the beginning next time
    //this allows us to distinguish between full and empty: nextEntryToLoad == nextEntryToTransmit means empty
    ptxFIFO->nextEntryToLoad = FIFOentry;
    return 0;
    //we reached the end but can continue loading from the top of the FIFO
    if ( FIFOentry >= ptxFIFO->numEntries)
    FIFOentry = 0;
    //load the control word
    ptxFIFO->FifoData[FIFOentry * 3] = *lclData++;
    //skip the high of the control word, the module only has a 16 bit field for control
    lclData++;
    //now put in the data
    ptxFIFO->FifoData[(FIFOentry * 3) + 2] = *lclData++;
    ptxFIFO->FifoData[(FIFOentry * 3) + 1] = *lclData++;
    numLoaded++;
    //we're done because we loaded everything the user asked for
    if (numLoaded >= numWords) {
    *actualLoaded = numLoaded;
    ptxFIFO->nextEntryToLoad = FIFOentry+1;
    return 0;
    //if we reached here, we're done because the FIFO is full
    *actualLoaded = numLoaded;
    ptxFIFO->nextEntryToLoad = FIFOentry;
    fclose (pFile);
    return 0;
     As you can see, I added a temporary diagnostic with the structures that were created in the "Handles by value" case, and print out the data.  I see what is expected, whichever of the options I pick in the CLN!  
    I understood (from the information in the two links I mentioned in my original post, and from the name of the option itself) that "array data pointer" should pass the array of data itself, without the dimSize field.  But that does not seem to be what is happening.
    Batya
    Attachments:
    ExcM4k Load Transmit FIFO.vi ‏15 KB

  • Text position in UITextView

    How can i get position of special word in UIText View in iphone SDK ?

    I don't think there's any direct method for determining the x-y coordinates of a particular run of text (whether selected or not) in UITextView. If I needed to do this, I would use an iterative algorithm. E.g., a simplified algorithm, which assumes the target text is one word, which can't be broken and can be rendered on a single line, might go something like this:
    1) Find the range of the target in the full text using [rangeOfString:options:range:|http://developer.apple.com/iphone/library/documen tation/Cocoa/Reference/Foundation/Classes/NSStringClass/Reference/NSString.html#//appleref/occ/instm/NSString/rangeOfString:options:range:];
    2) From the end of the range (1), get the substring of the full text that ends in the target using [substringToIndex:|http://developer.apple.com/iphone/library/documentation/Coco a/Reference/Foundation/Classes/NSStringClass/Reference/NSString.html#//apple_ref/doc/uid/20000154-substringToIndex];
    3) Get the bounding rectangle of the substring (2) using [sizeWithFont:constrainedToSize:lineBreakMode:|http://developer.apple.com/iphon e/library/documentation/UIKit/Reference/NSStringUIKit_Additions/Reference/Reference.html#//appleref/doc/uid/TP40006893-CH3-SW9];
    4) Remove words from the end of the substring (2) until the height of the bounding rectangle (3) is reduced. The length of the shortened substring should give you the index at the start of the line which contains the target; Save the reduced bounding rectangle as rUpper;
    5) Get the bounding rectangle of the line which begins at the start index (4), rLine, as well as the bounding rectangle of the target, rTarget, using [sizeWithFont:constrainedToSize:|http://developer.apple.com/iphone/library/docu mentation/UIKit/Reference/NSStringUIKit_Additions/Reference/Reference.html#//appleref/doc/uid/TP40006893-CH3-SW8];
    6) The target bounding rectangle, r, relative to the bounds of the text view object should then be obtained as:
    r.origin.x = rLine.size.width - rTarget.size.width;
    r.origin.y = rUpper.size.height;
    r.size.width = rTarget.size.width;
    r.size.height = rTarget.size.height;
    \- Ray

  • Simplifying a java.awt.Shape

    Hi,
    I have a problem where i have a shape created by an AREA object (basically unioning shapes to create a larger shape). The shape visually appears to be just a plain old square however the shape contains 200 segments!
    The algorithm i'm using tp examine the shape will be much more effecient of I can simplify the segments. I'm hoping there is some available software or utility that exists to take an existing java.awt.Shape that has redundant data and "simplify" it by removing superfulous information.
    i.e. if I did a line segmenet from 0,0 to 1,1 then a line segment from 1,1 to 2,2 that would be collapsed to a line segment from 0,0 to 2,2.
    I realize there's the PathIterator's flattening ability however I would like the simplifying shape to condense two quad curves to one cubic curve if possible and not necessarily change everything to lineto segments.
    Does anyone have any resources or information that might help me with this?
    Thanks!
    Trevor

    Hi
    Use the Java Threading Model ...
    This is a Sample Program that use Buffered Image as a Source
    import java.awt.Color;
    import java.util.ArrayList;
    public class Joint implements Runnable
            ArrayList points;
         byte startside,closedside;
         byte type; //0 line 1 arc
         boolean closed;
         Junction closedwith,parent;
         // Area shapeimage;
            int pixels[];
            int startpoint,width;
            Color color = Color.black;
            TraceResult result;
    public Joint(TraceResult Result,int pix[],int start,int w,Junction j)
            result = Result;
            startpoint = start;
            System.arraycopy(pix,0,pixels,0,pix.length);
            parent = j;
            //startside = side;
            points = new ArrayList();
            width = w;
    public boolean isonsamejuncion()
            return (parent==closedwith);
    public void run()
            int i;
            int p=nextPoint(0);
            while(p!=0)
            {       points.add(new Integer(p));
                    p = nextPoint(p);
                      /* Joint t = new Joint(pixels,width,parent);
                       Thread thread = new thread(t);
                       thread.start(); continue;*/
            /* else  { closed = false; closedwith = null; break;  }
    private final int nextPoint(int i)
    {       boolean M,N2,NE2,E2,SE2,S2,SW2,W2,NW2;
            int l=pixels.length;
            int N,E,S,W,NE,NW,SE,SW;
            int NP,EP,SP,WP,NEP,NWP,SEP,SWP;
            Junction j;
            if (!(M = color.equals(new Color(pixels))))
    closed=false;
    closedwith=null;
    return 0;
    //Trace points
    EP = i+1 ;
    WP = i-1 ;
    SP = i+width ;
    NP = i-width ;
    SEP = i+width+1 ;
    SWP = i+width-1 ;
    NEP = i-width+1 ;
    NWP = i-width-1 ;
    E =( (EP <= l) && color.equals(new Color(pixels[EP])) )?3:0;
    W =( (WP >= 0) && color.equals(new Color(pixels[WP])) )?11:0;
    S =( (SP <= l) && color.equals(new Color(pixels[SP])) )?5:0;
    N =( (NP >= 0) && color.equals(new Color(pixels[NP])) )?1:0;
    SE=( (SEP <= l) && color.equals(new Color(pixels[SEP])) )?300:0;
    SW=( (SWP >= 0) && color.equals(new Color(pixels[SWP])) )?500:0;
    NE=( (NEP <= l) && color.equals(new Color(pixels[NEP])) )?100:0;
    NW=( (NWP >= 0) && color.equals(new Color(pixels[NWP])) )?1100:0;
    int sum=N+E+S+W+NE+NW+SW+SE;
    switch (sum)
    case 1: //N
    case 3: //E
    case 5: //S
    case 11: //W
    case 100: //NE
    case 300: //SE
    case 500: //SW
    case 1100: //NW
    closed=false;
    closedwith=null;
    return 0;
    case 4: //N + E
    return points.contains(new Integer(EP))?NP:EP;
    case 6: //N + S
    return points.contains(new Integer(SP))?NP:SP;
    case 8: //S + E
    return points.contains(new Integer(EP))?SP:EP;
    case 16: //S + W
    return points.contains(new Integer(WP))?SP:WP;
    case 12: //N + W
    return points.contains(new Integer(WP))?NP:WP;
    case 14: //W + E
    return points.contains(new Integer(EP))?WP:EP;
    case 400: //NE + SE
    return points.contains(new Integer(SEP))?NEP:SEP;
    case 600: //NE + SW
    return points.contains(new Integer(SWP))?NEP:SWP;
    case 800: //SW + SE
    return points.contains(new Integer(SEP))?SWP:SEP;
    case 1600: //SW + NW
    return points.contains(new Integer(NWP))?SWP:NWP;
    case 1200: //NE + NW
    return points.contains(new Integer(NWP))?NEP:NWP;
    case 1400: //NW + SE
    return points.contains(new Integer(SEP))?NWP:SEP;
    case 101: //NE + N
    return points.contains(new Integer(NP))?NEP:NP;
    case 301: //SE + N
    return points.contains(new Integer(NP))?SEP:NP;
    case 501: //SW + N
    return points.contains(new Integer(NP))?SWP:NP;
    case 1101: //NW + N
    return points.contains(new Integer(NP))?NWP:NP;
    case 103: //NE + E
    return points.contains(new Integer(EP))?NEP:EP;
    case 303: //SE + E
    return points.contains(new Integer(EP))?SEP:EP;
    case 503: //SW + E
    return points.contains(new Integer(EP))?SWP:EP;
    case 1103: //NW + E
    return points.contains(new Integer(EP))?NWP:EP;
    case 105: //NE + S
    return points.contains(new Integer(SP))?NEP:SP;
    case 305: //SE + S
    return points.contains(new Integer(SP))?SEP:SP;
    case 505: //SW + S
    return points.contains(new Integer(SP))?SWP:SP;
    case 1105: //NW + S
    return points.contains(new Integer(SP))?NWP:SP;
    case 111: //NE + W
    return points.contains(new Integer(WP))?NEP:WP;
    case 311: //SE + W
    return points.contains(new Integer(WP))?SEP:WP;
    case 511: //SW + W
    return points.contains(new Integer(WP))?SWP:WP;
    case 1111: //NW + W
    return points.contains(new Integer(WP))?NWP:WP;
    case 15: //N + E + W
    if(points.contains(new Integer(WP)))
    N2 = NP-width >0 && color.equals(new Color(pixels[NP-width]));
    E2 = EP+1 < 1 && color.equals(new Color(pixels[EP+1]));
    if (N2 && E2)
    j=new Junction(i,NP,EP,-1,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,EP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (N2)
    return NP;
    else
    return EP;
    }else if(points.contains(new Integer(EP)))
    N2 = NP-width >0 && color.equals(new Color(pixels[NP-width]));
    W2 = WP-1 > 0 && color.equals(new Color(pixels[WP-1]));
    if (N2 && W2)
    j=new Junction(i,NP,EP,-1,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,WP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (N2)
    return NP;
    else
    return WP;
    }else if(points.contains(new Integer(NP)))
    W2 = WP-1 >0 && color.equals(new Color(pixels[WP-1]));
    E2 = EP+1 < 1 && color.equals(new Color(pixels[EP+1]));
    if (W2 && E2)
    j=new Junction(i,NP,EP,-1,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,WP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,EP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (W2)
    return WP;
    else
    return EP;
    case 9: //N + E + S
    if(points.contains(new Integer(SP)))
    N2 = NP-width >0 && color.equals(new Color(pixels[NP-width]));
    E2 = EP+1 < 1 && color.equals(new Color(pixels[EP+1]));
    if (N2 && E2)
    j=new Junction(i,NP,EP,SP,-1,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,EP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (N2)
    return NP;
    else
    return EP;
    }else if(points.contains(new Integer(EP)))
    N2 = NP-width >0 && color.equals(new Color(pixels[NP-width]));
    S2 = SP+width > 0 && color.equals(new Color(pixels[SP+width]));
    if (N2 && S2)
    j=new Junction(i,NP,EP,SP,-1,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,SP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (N2)
    return NP;
    else
    return SP;
    }else if(points.contains(new Integer(NP)))
    S2 = SP+width >0 && color.equals(new Color(pixels[SP+width]));
    E2 = EP+1 < 1 && color.equals(new Color(pixels[EP+1]));
    if (S2 && E2)
    j=new Junction(i,NP,EP,SP,-1,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,SP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,EP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (S2)
    return SP;
    else
    return EP;
    case 17: //N + W + S
    if(points.contains(new Integer(SP)))
    N2 = NP-width >0 && color.equals(new Color(pixels[NP-width]));
    W2 = WP-1 > 0 && color.equals(new Color(pixels[WP-1]));
    if (N2 && W2)
    j=new Junction(i,NP,-1,SP,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,WP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (N2)
    return NP;
    else
    return WP;
    }else if(points.contains(new Integer(WP)))
    N2 = NP-width >0 && color.equals(new Color(pixels[NP-width]));
    S2 = SP+width <l && color.equals(new Color(pixels[SP+width]));
    if (N2 && S2)
    j=new Junction(i,NP,-1,SP,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,SP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (N2)
    return NP;
    else
    return SP;
    }else if(points.contains(new Integer(NP)))
    S2 = SP+width >l && color.equals(new Color(pixels[SP+width]));
    W2 = WP-1 > 0 && color.equals(new Color(pixels[WP-1]));
    if (W2 && S2)
    j=new Junction(i,NP,-1,SP,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,SP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,WP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (S2)
    return SP;
    else
    return WP;
    case 19: //E + S + W
    if(points.contains(new Integer(SP)))
    W2 = WP+width <l && color.equals(new Color(pixels[WP+width]));
    E2 = EP+1 < 1 && color.equals(new Color(pixels[EP+1]));
    if (W2 && E2)
    j=new Junction(i,-1,EP,SP,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,WP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,EP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (W2)
    return WP;
    else
    return EP;
    }else if(points.contains(new Integer(EP)))
    W2 = WP+width <l && color.equals(new Color(pixels[WP+width]));
    S2 = SP+width <l && color.equals(new Color(pixels[SP+width]));
    if (W2 && S2)
    j=new Junction(i,-1,EP,SP,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,WP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,SP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (W2)
    return WP;
    else
    return SP;
    }else if(points.contains(new Integer(WP)))
    S2 = SP+width <l && color.equals(new Color(pixels[SP+width]));
    E2 = EP+1 < 1 && color.equals(new Color(pixels[EP+1]));
    if (S2 && E2)
    j=new Junction(i,-1,EP,SP,WP,-1,-1,-1,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,SP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,EP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (S2)
    return SP;
    else
    return EP;
    case 20: //N + E + S +W
    case 1500: //NE + SE + NW
    if(points.contains(new Integer(NW)))
    NE2 = NEP-width+1 < 0 && color.equals(new Color(pixels[NEP-width+1]));
    SE2 = SEP+width+1 < 1 && color.equals(new Color(pixels[EP+width+1]));
    if (NE2 && SE2)
    j=new Junction(i,-1,-1,-1,-1,NEP,SEP,-1,NWP,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NEP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,SEP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (NE2)
    return NEP;
    else
    return SEP;
    }else if(points.contains(new Integer(SEP)))
    NE2 = NEP-width+1 >0 && color.equals(new Color(pixels[NP-width+1]));
    NW2 = NWP-width-1 > 0 && color.equals(new Color(pixels[NWP-width-1]));
    if (NE2 && NW2)
    j=new Junction(i,-1,-1,-1,-1,NE,SE,-1,NW,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NEP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,NWP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (NE2)
    return NEP;
    else
    return NWP;
    }else if(points.contains(new Integer(NEP)))
    NW2 = NWP-width-1 >0 && color.equals(new Color(pixels[WP-width-1]));
    SE2 = SEP+width+1 < 1 && color.equals(new Color(pixels[SEP+width+1]));
    if (NW2 && SE2)
    j=new Junction(i,-1,-1,-1,-1,NE,SE,-1,NW,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NWP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,SEP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (NW2)
    return NWP;
    else
    return SEP;
    case 900: //NE + SE + SW
    if(points.contains(new Integer(SWP)))
    NE2 = NEP-width+1 >0 && color.equals(new Color(pixels[NEP-width+1]));
    SE2 = SEP+width+1 < 1 && color.equals(new Color(pixels[SEP+width+1]));
    if (NE2 && SE2)
    j=new Junction(i,-1,-1,-1,-1,NEP,SEP,SWP,-1,3,result);
    if(result.contains(j))
    closedwith=j;
    closed=true;
    return 0;
    else
    result.add(j);
    Joint j1=new Joint(result,pixels,NEP,width,j);
    Thread t=new Thread(j1);
    t.start();
    Joint j2=new Joint(result,pixels,SEP,width,j);
    Thread t1=new Thread(j2);
    t1.start();
    }else if (NE2)
    return NEP;
    else

  • SDO_UTIL.SIMPLIFY - 101 Uses (almost)

    SDO_UTIL.SIMPLIFY
    “Simplifies the input geometry, based on a threshold value, using the Douglas-Peucker algorithm.”
    This is an understated description if there is one. This function can do much more for you than just simplify the geometry, it will also convert arcs to line stings, eliminate duplicate verticies, and correct many overlapping edge polygon problems.
    I “discovered” this additional functionality while trying to get a process down to import reference ESRI shapefile data (GeoBase CIP's) stored in state-plane format into OS (Oracle Spatial) using Lat/Long. Most of the problems I encountered were due to overlapping polygon edges, duplicate verticies, and arcs in line strings. At first, I discreetly defused these issues by finding the errors (with code) and then fixing them based on the returned error codes. This was painfully slow and a real pain to code.
    Then I took a look at the incoming data, and determined that many times, the drafters (possibly from a CAD to GIS conversion) really went overboard and included many times more points than necessary for the accuracy I was interested in for the reference data. I looked at several of the simplify options and since I wanted to simplify the data in-place using an update statement, I choose this one. Then once, I ran the simplify command out of order by accident (before the arc/duplicate/overlap routine). Not only did it simply the data, it also “fixed” all the other problems as well!
    So – note to Oracle staff – great job! You might want to update the documentation to mention all the things it does while simplifying the data, as this is VERY useful for migrating troublesome data. However, I noticed that it can overtake all the memory (and take forever to run) on your database box if you make the mistake of specifying the same values for threshold and tolerance. The docs do state that the tolerance “Must not be greater than threshold.”, but I'd add that they also should not be the same.
    As always, YMMV...
    Bryan

    tdsacilowski wrote:
    All together there are about 20 machines that display a page that has one of the above 5 second refreshes. The application is also public; there is no authentication. From my understanding about how APEX handles sessions there is a max session length (8 hours in my case) even for public sessions. As a page is rendered, a hidden form variable is created called p_instance and the AJAX calls send this to the server to process the request within the active session. In theory, the application shouldn't be generating a lot of new sessions since once a page is loaded it is used simple to display an updating value. In other words, there's no user interaction. No page reloads, no new items being set in session state.
    no interaction, 24/7 uptime, refreshing every 5s, and it is all public.....
    I'd almost look at a slightly different architecture.
    option one:
    have a basic, static web page that calls an APEX REST service.
    This html file and any neccessary css, js files will reside on the same webserver as the APEX listener, but in a different WAR file.
    option two:
    make a simple java swing app using JDBC to connect directly to the database.
    use Oracle Wallet technology so you don't have to hardcode the name/password in plain text.
    have the DBA create an account with very limited access and a profile to guarantee it will never suck-up DB resources.
    *** IIRC -- the OCI version includes the capability of triggering an event (in Java) when a table gets update. ****
    APEX is a very good tool.
    But, for your case, it sounds like it is overkill for your requirements.
    MK

  • Simple algorithm help to replace hardcoding

    How can this be simplified into simple algorithm?
    public void AI() {
            count++;
            if (count > 4 && randomMoveDecider() == true) {
                randomMove();
            } else if (buttons[1].getText().equals("O") && buttons[2].getText().equals("O") && buttons[3].getText().equals("")) {
                buttons[3].setText("O");
                buttons[3].setEnabled(false);
                board.setButton3("O");
            } else if (buttons[4].getText().equals("O") && buttons[5].getText().equals("O") && buttons[6].getText().equals("")) {
                buttons[6].setText("O");
                buttons[6].setEnabled(false);
                board.setButton6("O");
            } else if (buttons[7].getText().equals("O") && buttons[8].getText().equals("O") && buttons[9].getText().equals("")) {
                buttons[9].setText("O");
                buttons[9].setEnabled(false);
                board.setButton9("O");
            } else if (buttons[2].getText().equals("O") && buttons[3].getText().equals("O") && buttons[1].getText().equals("")) {
                buttons[1].setText("O");
                buttons[1].setEnabled(false);
                board.setButton1("O");
            } else if (buttons[5].getText().equals("O") && buttons[6].getText().equals("O") && buttons[4].getText().equals("")) {
                buttons[4].setText("O");
                buttons[4].setEnabled(false);
                board.setButton4("O");
            } else if (buttons[8].getText().equals("O") && buttons[9].getText().equals("O") && buttons[7].getText().equals("")) {
                buttons[7].setText("O");
                buttons[7].setEnabled(false);
                board.setButton7("O");
            } else if (buttons[1].getText().equals("O") && buttons[3].getText().equals("O") && buttons[2].getText().equals("")) {
                buttons[2].setText("O");
                buttons[2].setEnabled(false);
                board.setButton2("O");
            } else if (buttons[4].getText().equals("O") && buttons[6].getText().equals("O") && buttons[5].getText().equals("")) {
                buttons[5].setText("O");
                buttons[5].setEnabled(false);
                board.setButton5("O");
            } else if (buttons[7].getText().equals("O") && buttons[9].getText().equals("O") && buttons[8].getText().equals("")) {
                buttons[8].setText("O");
                buttons[8].setEnabled(false);
                board.setButton8("O");
            } else if (buttons[1].getText().equals("O") && buttons[4].getText().equals("O") && buttons[7].getText().equals("")) {
                buttons[7].setText("O");
                buttons[7].setEnabled(false);
                board.setButton7("O");
            } else if (buttons[2].getText().equals("O") && buttons[5].getText().equals("O") && buttons[8].getText().equals("")) {
                buttons[4].setText("O");
                buttons[4].setEnabled(false);
                board.setButton4("O");
            } else if (buttons[3].getText().equals("O") && buttons[6].getText().equals("O") && buttons[9].getText().equals("")) {
                buttons[9].setText("O");
                buttons[9].setEnabled(false);
                board.setButton9("O");
            } else if (buttons[4].getText().equals("O") && buttons[7].getText().equals("O") && buttons[1].getText().equals("")) {
                buttons[1].setText("O");
                buttons[1].setEnabled(false);
                board.setButton1("O");
            } else if (buttons[5].getText().equals("O") && buttons[8].getText().equals("O") && buttons[2].getText().equals("")) {
                buttons[2].setText("O");
                buttons[2].setEnabled(false);
                board.setButton2("O");
            } else if (buttons[6].getText().equals("O") && buttons[9].getText().equals("O") && buttons[3].getText().equals("")) {
                buttons[3].setText("O");
                buttons[3].setEnabled(false);
                board.setButton3("O");
            } else if (buttons[1].getText().equals("O") && buttons[7].getText().equals("O") && buttons[4].getText().equals("")) {
                buttons[4].setText("O");
                buttons[4].setEnabled(false);
                board.setButton4("O");
            } else if (buttons[2].getText().equals("O") && buttons[8].getText().equals("O") && buttons[5].getText().equals("")) {
                buttons[5].setText("O");
                buttons[5].setEnabled(false);
                board.setButton5("O");
            } else if (buttons[3].getText().equals("O") && buttons[9].getText().equals("O") && buttons[6].getText().equals("")) {
                buttons[6].setText("O");
                buttons[6].setEnabled(false);
                board.setButton6("O");
            } else if (buttons[1].getText().equals("O") && buttons[5].getText().equals("O") && buttons[9].getText().equals("")) {
                buttons[9].setText("O");
                buttons[9].setEnabled(false);
                board.setButton9("O");
            } else if (buttons[5].getText().equals("O") && buttons[9].getText().equals("O") && buttons[1].getText().equals("")) {
                buttons[1].setText("O");
                buttons[1].setEnabled(false);
                board.setButton1("O");
            } else if (buttons[1].getText().equals("O") && buttons[9].getText().equals("O") && buttons[5].getText().equals("")) {
                buttons[5].setText("O");
                buttons[5].setEnabled(false);
                board.setButton5("O");That is only some of it. :(
    But the point is for the AI to check the grid on a tic tac toe grid 3/3 and make the best move(win or stop wins)

    tjacobs01 wrote:
    private boolean buttonTest(JButton button1, JButton button2, JButton button3) {
    if (button1.getText().equals("O") && button2.getText().equals("O") && button3.getText().equals("")) {
    button3.setText("O");
    button3.setEnabled(false);
    return true;
    return false;Edited by: tjacobs01 on Dec 4, 2009 1:39 PMGreat ;)

  • Simplify geometry

    I'm trying to simplify a layer with line (spaghetti) geometries that are geodetic (SRID 8307).
    1. Does the SDO_SAM.SIMPLIFY_LAYER work with Geodetic data?
    When I try to use sdo_sam.simplify_layer function, the number of vertices does not change, regardless of the "pct_area_change_limit" I use (the only parameter where I can change the value). I even tried 100 (which I take to mean 100%).
    execute sdo_sam.simplify_layer('TRACK_TEST','SHAPE','SMPL_SHAPE', '10', '100');
    Maybe this is only applicable for polygon data?
    2. Should I use SDO_UTIL.SIMPLIFY, instead, for geodetic data?
    I was able to create a simplified layer using SDO_UTIL.SIMPLIFY, but I had understood that the SDO_SAM.SIMPLIFY_LAYER was simply a wrapper around SDO_UTIL.SIMPLIFY. I incrementally tried increasingly larger values for the parameters in SDO_UTIL.SIMPLIFY, and it ended up that I had to change the threshold parameter to 10000, and the tolerance parameter to 9999 before I saw a significant difference in the number of vertices.
    CREATE TABLE TRACK_TEST_2
    AS SELECT ID,
    sdo_util.simplify(
    MDSYS.SDO_GEOMETRY(
    A.SHAPE.SDO_GTYPE,A.SHAPE.SDO_SRID,A.SHAPE.SDO_POINT,A.SHAPE.SDO_ELEM_INFO,A.SHAPE.SDO_ORDINATES),
    10000,9999) SMPL_SHAPE
    FROM TRACK_TEST A;
    3. Why are the parameters controlling the functions different for SDO_SAM.SIMPLIFY_LAYER (commit interval, pct_area_change_limit)
    SDO_SAM.SIMPLIFY_GEOMETRY (tolerance,pct_area_change_limit)
    and SDO_UTIL.SIMPLIFY (threshold, tolerance)?
    I tried changing the tolerance in my layer's metadata, but that didn't seem to affect sdo_sam.simplify_layer.
    4. Perhaps my data are not suited for simplifying, but I was hoping to achieve data that displayed more quickly in an on-line map viewer. Are the SIMPLIFY functions best suited to geometries with very closely spaced vertices?
    Any insight would be appreciated!
    --Nancy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi Nancy,
    first of all: it works... :)
    ok, you have between point 1 and point 2 a difference in Longitude with 0.0001 (-4.4782 -4.4783). This is roughly approached 11m (40.000.000 m/360°*0.0001). If you use a threshold oh 10m and then a threshold of 20m you will see the difference of the result (or 100m, 10000m, 100000m)...
    The number of points will be reduced by the algorithm, if there are possible distances to reduce!
    for douglas peuker you should see:
    http://geometryalgorithms.com/Archive/algorithm_0205/algorithm_0205.htm#Douglas-Peucker%20Algorithm
    create table TEST_SP(
    ID NUMBER NOT NULL,
    GEOM MDSYS.SDO_GEOMETRY,
    constraint PK_TESTSP primary key(ID));
    insert into MDSYS.USER_SDO_GEOM_METADATA values ('TEST_SP', 'GEOM',
    MDSYS.SDO_DIM_ARRAY (
    MDSYS.SDO_DIM_ELEMENT ('Longitude', -180, 180, .05),
    MDSYS.SDO_DIM_ELEMENT ('Latitude', -90, 90, .05)),8307);
    create index TEST_SP_GIDX on TEST_SP(GEOM) indextype is MDSYS.SPATIAL_INDEX parameters('sdo_indx_dims=2');
    INSERT INTO TEST_SP(ID,GEOM)
    VALUES (1,
           MDSYS.SDO_GEOMETRY(2006, 8307, NULL,
           MDSYS.SDO_ELEM_INFO_ARRAY(1, 2, 1),
           MDSYS.SDO_ORDINATE_ARRAY(-4.4782, 48.383, -4.4783, 48.3839, -4.5072, 48.3523, -4.8323, 48.2802, -4.9683, 48.2977
           , -5.2159, 48.4632, -5.4231, 48.9394, -5.6304, 49.4157, -5.8376, 49.8919, -5.8881, 50.016, -5.8588, 50.5097, -5.8296
           , 51.0035, -5.8003, 51.4972, -5.7041, 51.9855, -5.608, 52.4738, -5.5118, 52.9621, -5.4198, 53.3168, -5.3821, 53.3369
           , -5.3164, 53.6902, -5.2506, 54.0435, -5.1849, 54.3968, -5.4752, 54.7332, -5.7656, 55.0696, -6.0559, 55.406, -6.5756
           , 55.4709, -6.8982, 55.76, -7.2207, 56.0492, -7.5433, 56.3383, -7.2575, 56.7691, -6.9716, 57.2, -6.6858, 57.6308, -6.6665
           , 57.6427, -6.2458, 57.8083, -5.825, 57.9738, -5.5861, 58.4546, -5.3473, 58.9355, -5.1084, 59.4163, -4.9137, 59.7915
           , -4.719, 60.1667, -4.5436, 60.5136, -4.3682, 60.8605, -4.1047, 61.3391, -3.8412, 61.8176, -3.5777, 62.2962, -3.361
           , 62.7598, -3.8819, 63.1987, -4.4027, 63.6375, -4.9236, 64.0764, -5.4563, 64.4946, -5.989, 64.9128, -5.9889, 64.9258
           , -5.3195, 65.2554, -4.65, 65.5851, -3.9806, 65.9147, -3.7081, 66.3963, -3.4357, 66.878, -3.1632, 67.3596, -3.0062
           , 67.7413, -2.9647, 68.0694, -2.9232, 68.3976, -2.8955, 68.7173, -2.887, 68.8462, -2.8182, 69.3409, -2.7494, 69.8357
           , -2.6806, 70.3304, -2.6327, 70.7036, -2.5849, 71.0769, -2.537, 71.4501, -2.4891, 71.8233, -2.4831, 71.8485, -2.4675
           , 71.8937, -2.4678, 71.9014, -2.4799, 71.9143, -2.4814, 71.9087, -2.4772, 71.9077, -1.9743, 71.7427, -1.5918, 71.8198
           , -.3136, 72.0398, .9646, 72.2599, 2.2428, 72.4799, 3.3439, 72.6617, 4.4449, 72.8435, 4.4565, 72.8586, 4.418, 72.8691
           , 2.9688, 72.6301, 1.5196, 72.3912, .0704, 72.1522, -.6649, 72.0252, -1.4002, 71.8982, -1.417, 71.8855, -1.3403, 71.8332
           , -1.2964, 71.8326, .1123, 72.074, 1.5209, 72.3153, 2.9296, 72.5567, 3.7046, 72.6857, 4.4796, 72.8146, 4.5257, 72.8115
           , 4.5476, 72.799, 4.5273, 72.786, 3.696, 72.6769, 3.6234, 72.638, 2.2485, 72.4053, .8735, 72.1727, -.5014, 71.94, -.5454
           , 71.9384, -.7357, 72.0499, .4759, 72.2537, 1.6876, 72.4575, 2.8992, 72.6613, 2.9211, 72.6507, 1.9359, 72.4834, .9506
           , 72.316, -.0346, 72.1487, -.028, 72.1346, .009, 72.1265, .9959, 72.2905, 1.9827, 72.4546, 2.9696, 72.6186, 3.0143
           , 72.6149, 3.0332, 72.6001, 3.002, 72.5875, 2.0095, 72.42, 1.0169, 72.2524, .0244, 72.0849, .0186, 72.0717, .0446
           , 72.0605, .0888, 72.0604, 1.0737, 72.2246, 2.0587, 72.3887, 3.0436, 72.5529, 3.111, 72.5134, 2.14, 72.3481, 1.169
           , 72.1829, .198, 72.0176, .2107, 72.0031, .2599, 71.9984, 1.2471, 72.1609, 2.2343, 72.3234, 3.2215, 72.4859, 3.2602
           , 72.478, 3.2657, 72.4632, 2.278, 72.2965, 1.2903, 72.1297, .3026, 71.963, .2758, 71.952, .2828, 71.9386, .3297, 71.9323
           , 1.2185, 72.0805, 1.7223, 72.1642, 2.503, 72.2919, 3.2837, 72.4196, 3.3688, 72.3642, 2.4037, 72.2013, 1.4386, 72.0384
           , .4735, 71.8755, .5692, 71.8254, .6111, 71.8254, 1.125, 71.9124, 2.0029, 72.0607, 2.7263, 72.1807, 2.7578, 72.1925
           , 2.2202, 72.4803, 1.6826, 72.7682, 1.5122, 72.7334, 2.1082, 72.3975, 2.7043, 72.0615, 3.3003, 71.7256, 3.3001, 71.7124
           , 3.2157, 71.6973, 3.1737, 71.6952, 2.3869, 72.1318, 1.6002, 72.5685, .8134, 73.0051, .5468, 73.1462, .3685, 73.1217
           , .3595, 73.1095, 1.1552, 72.6727, 1.9509, 72.2359, 2.7466, 71.7991, 3.2359, 71.5183, 3.2114, 71.5062, 3.0948, 71.4854
           , 3.0524, 71.4834, 2.2702, 71.9181, 1.488, 72.3528, .7058, 72.7875, .121, 73.0845, -.0487, 73.0569, .2024, 72.9178
           , .388, 72.9389, .4762, 72.9269, .5364, 72.89, .3319, 72.8554, .3409, 72.8406, 1.0959, 72.4252, 1.8508, 72.0099, 2.6058
           , 71.5945, 2.4501, 71.5637, 2.4042, 71.566, 1.6172, 71.9987, .8302, 72.4313, .0432, 72.864, -.1008, 72.9388, -.1515
           , 72.9379, -.6602, 72.8529, -.6974, 72.8597, -.8222, 72.9223, -.8075, 72.9346, -.7236, 72.9474, -.5355, 72.9736, -.5009
           , 72.9844, -.4884, 72.9991, -.5006, 73.0334, -.3954, 72.9838, .2817, 72.6227, .9588, 72.2616, 1.6359, 71.9005, 1.603, 71.8921
           , 1.4702, 71.8735, 1.4273, 71.8777, .8944, 72.1673, .3614, 72.4568, .3643, 72.4713, 1.4427, 72.6505, 2.521, 72.8297, 2.6168
           , 72.7773, 2.5908, 72.767, 1.1703, 72.5281, -.2502, 72.2891, -.2771, 72.2779, -.2594, 72.2632, -.212, 72.2585, .8306
           , 72.4334, 1.8733, 72.6083, 2.9159, 72.7832, 2.9674, 72.7852, 2.9902, 72.7712, 2.9657, 72.7592, 1.9165, 72.5801
           , .8673, 72.4009, -.1819, 72.2218, -.1901, 72.2083, -.1611, 72.1973, -.1161, 72.1973, .9307, 72.3749, 1.9774, 72.5525
           , 3.0242, 72.7301, 3.0573, 72.7214, 3.3182, 72.5681, 2.3711, 72.4083, 1.6896, 72.4105, 1.4702, 72.2525, .0765, 72.0164
           , -1.3172, 71.7804, -1.5303, 71.9025, -1.5214, 71.9157, -.7819, 72.0493, -.7584, 72.0625, -.1361, 72.1707, -.0875, 72.1713
           , .0304, 72.0919, .0141, 72.0786, -.9506, 71.905, -1.9152, 71.7315, -1.9596, 71.7391, -1.9712, 71.7533, -1.9458, 71.7646
           , -1.8996, 71.7677, -1.8199, 71.7848, -1.7743, 71.7845, -1.7465, 71.7709, -1.7419, 71.7559, -1.8251, 71.744, -1.8392, 71.73
           , -1.7998, 71.7272, -1.7953, 71.7285, -1.6374, 71.7675, -1.6548, 71.7691, -1.8372, 71.7472, -1.8217, 71.746, -1.8177, 71.7408
           , -1.7915, 71.748, -1.8019, 71.7254, -1.9911, 71.2377, -2.1803, 70.7499, -2.3695, 70.2622, -2.55, 69.7684, -2.7305, 69.2745
           , -2.911, 68.7807, -3.0756, 68.2892, -3.2401, 67.7976, -3.4047, 67.3061, -3.5591, 66.8129, -3.7134, 66.3197, -3.8678, 65.8265
           , -4.0106, 65.3313, -4.1534, 64.8361, -4.2962, 64.3409, -4.3917, 64.0736, -4.5101, 63.6701, -4.6284, 63.2665, -4.7468, 62.863
           , -4.8133, 62.5646, -4.8797, 62.2661, -5.0123, 61.8243, -5.1449, 61.3824, -5.2784, 60.8876, -5.412, 60.3927, -5.5455, 59.8979
           , -5.6914, 59.4059, -5.8373, 58.914, -5.9832, 58.422, -6.1319, 58.0188, -6.1481, 58.0064, -6.4952, 57.9001, -6.8148, 57.4395
           , -7.1344, 56.979, -7.454, 56.5184, -7.5405, 56.3236, -7.1569, 56.009, -6.7734, 55.6943, -6.3898, 55.3797, -6.1153, 55.3535
           , -5.8063, 55.0412, -5.4973, 54.7289, -5.1883, 54.4166, -5.3286, 53.9254, -5.4688, 53.4341, -5.6091, 52.9429, -5.7337, 52.4541
           , -5.8583, 51.9652, -5.9829, 51.4764, -5.9945, 50.9804, -6.0062, 50.4845, -6.0178, 49.9885, -5.7687, 49.5197, -5.5196, 49.0509
           , -5.2705, 48.5821
    -- Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    -- Threshold value to be used for the geometry simplification.
    -- Should be a positive number. (Zero causes the input geometry to be returned.)
    -- If the input geometry is geodetic, the value is the number of meters;
    -- if the input geometry is non-geodetic, the value is the number of units associated with the data.
    -- Tolerance reflects the distance that two points can be apart and still be considered the same
    -- MUST NOT! be greater than threshold, or null (then internally = 0.005)
    --> You have defined a tolerance in metadata with 0.05; so why don't use here?
            SELECT ID,
                   sdo_util.simplify(
                                     GEOM,
                                     10000,0.05) SMPL_SHAPE
                  FROM TEST_SP A;
             1
    SDO_GEOMETRY(2006, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(
    -4,4782378, 48,3825828, -4,8323474, 48,2797711, -5,2159566, 48,4627829, -5,88816
    28, 50,0156972, -5,1849215, 54,3967266, -6,0559248, 55,4059499, -6,5756301, 55,4
    708485, -7,5433349, 56,3382611, -6,6858165, 57,6307846, -5,8250091, 57,9737903,
    -3,3610006, 62,7598027, -5,9890247, 64,9128292, -3,9806117, 65,9147493, -3,16320
    41, 67,3597054, -2,4798621, 71,9148546, -1,9742256, 71,7432283, 4,41878772, 72,8
    698623, -1,416879, 71,8860517, 4,52649053, 72,8122526, -,50120336, 71,9405632, -
    ,73551748, 72,0504801, 2,89978127, 72,6620086, -,03435262, 72,1492992, 2,97018311
    , 72,6193014, ,018847266, 72,0722867, 3,04418215, 72,5535901, ,198259139, 72,0181787
    , 3,22209193, 72,4865797, ,276061466, 71,9525685, 3,28428939, 72,4202686, ,473772831
    , 71,8760574, 2,72680263, 72,1813226, 1,68306421, 72,7689189, 3,30060056
    , 71,7129527, ,547178691, 73,1469855, 3,05285269, 71,4839162, ,121326784, 73,085271
    , 2,45051033, 71,5642229, -,10050751, 72,9395414, -,82198316, 72,9230354, -,50034338
    , 73,0341583, 1,47055648, 71,874063, ,364605226, 72,4719567, 2,52156221, 72,8304369
    , -,24996327, 72,2897221, 2,91649976, 72,7839314, -,18986264, 72,2089086
    , 3,02480439, 72,7308224, 3,31881376, 72,5687954, -1,3170745, 71,7809355, -1,5212864
    , 71,9162563, -,13586013, 72,1713025, ,014347302, 72,0791878, -1,9711251
    , 71,75383, -1,6372994, 71,7680328, -3,7134102, 66,319762, -5,5455029, 59,897899
    , -6,1319107, 58,0187899, -6,4952136, 57,9000878, -7,540535, 56,3235608, -5,1883214
    , 54,4165272, -5,9829533, 51,4761912, -6,0178661, 49,9881936, -5,2705573, 48,5816924))
            SELECT ID,
                   sdo_util.simplify(
                                     GEOM,
                                     1000,0.05) SMPL_SHAPE
                  FROM TEST_SP A;
             1
    SDO_GEOMETRY(2006, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(
    -4,4782378, 48,3825828, -4,5072387, 48,35188, -4,8323474, 48,2797711, -4,9683509
    , 48,2972713, -5,2159566, 48,4627829, -5,8881628, 50,0156972, -5,8003495, 51,496
    9942, -5,5118342, 52,9619711, -5,4198306, 53,3166867, -5,3821299, 53,3367877, -5
    ,1849215, 54,3967266, -6,0559248, 55,4059499, -6,5756301, 55,4708485, -7,5433349
    , 56,3382611, -6,6858165, 57,6307846, -5,8250091, 57,9737903, -4,7190009, 60,166
    6997, -3,5777005, 62,2962013, -3,3610006, 62,7598027, -4,4027049, 63,6375088, -5
    ,9890247, 64,9128292, -3,9806117, 65,9147493, -3,1632041, 67,3597054, -3,006201,
    67,7414256, -2,4798621, 71,9148546, -1,9742256, 71,7432283, ,964944602, 72,2605
    232, 2,24328978, 72,4805703, 4,44568645, 72,8442578, 4,41878772, 72,8698623, 1,5
    2000878, 72,3918494, -1,416879, 71,8860517, -1,3401746, 71,8337437, -1,2962712,
    71,8331437, ,112555419, 72,0745875, 1,52130154, 72,3159363, 4,52649053, 72,81225
    26, 4,52808622, 72,7867478, 3,69667156, 72,6776188, 3,6240575, 72,638711, 2,2489
    818, 72,4059572, -,50120336, 71,9405632, -,54520702, 71,9389628, -,73551748, 72,
    0504801, ,476199597, 72,2543194, 2,89978127, 72,6620086, 2,92168221, 72,6514068,
    1,93635925, 72,4840686, -,03435262, 72,1492992, ,009249796, 72,1270957, 2,97018
    311, 72,6193014, 3,03378745, 72,6007986, 3,00258239, 72,588196, ,024648569, 72,0
    854889, ,018847266, 72,0722867, ,089052559, 72,0609852, 3,04418215, 72,5535901,
    3,11158397, 72,5140836, ,198259139, 72,0181787, ,260163137, 71,9989759, 3,222091
    93, 72,4865797, 3,26629348, 72,4638761, ,276061466, 71,9525685, ,329964682, 71,9
    328656, 3,28428939, 72,4202686, 3,36939068, 72,3648597, ,473772831, 71,8760574,
    ,569477285, 71,82595, ,611380719, 71,8259502, 2,72680263, 72,1813226, 2,75830711
    , 72,1931249, 1,68306421, 72,7689189, 1,5126426, 72,7341112, 3,30060056, 71,7129
    527, 3,17418717, 71,6957489, 1,60063452, 72,5691815, ,547178691, 73,1469855, ,35
    9854829, 73,1102772, 1,95133441, 72,2365257, 3,23637231, 71,518823, 3,05285269,
    71,4839162, 1,48840202, 72,3534425, ,121326784, 73,085271, -,04839361, 73,057664
    8, ,202722649, 72,9185387, ,388343833, 72,9396437, ,47655216, 72,9276418, ,53675
    5404, 72,890735, ,33223128, 72,8561273, ,341231045, 72,8413245, 1,09627118, 72,4
    258526, 2,60622659, 71,5950287, 2,45051033, 71,5642229, 2,40460672, 71,5665229,
    1,61758053, 71,999284, -,10050751, 72,9395414, -,65997036, 72,8536226, -,8219831
    6, 72,9230354, -,50064638, 72,9851486, -,50034338, 73,0341583, 1,63627318, 71,90
    10684, 1,47055648, 71,874063, 1,42765317, 71,8782634, ,894730643, 72,1679072, ,3
    64605226, 72,4719567, 2,52156221, 72,8304369, 2,61736591, 72,7780277, 2,59136171
    , 72,7677256, -,24996327, 72,2897221, -,25916558, 72,2638176, -,21176165, 72,259
    117, 2,91649976, 72,7839314, 2,96800578, 72,7859322, 2,96630196, 72,7599273, -,1
    8166113, 72,2224109, -,18986264, 72,2089086, -,1158568, 72,197907, ,931051106, 7
    2,3755428, 3,02480439, 72,7308224, 3,31881376, 72,5687954, 2,37159441, 72,408958
    7, 1,69002721, 72,411154, 1,47059079, 72,2531252, -1,3170745, 71,7809355, -1,521
    2864, 71,9162563, -,13586013, 72,1713025, -,08725586, 72,1719028, ,014347302, 72
    ,0791878, -1,9151213, 71,7320267, -1,9711251, 71,75383, -1,7742095, 71,7850351,
    -1,7418077, 71,7564308, -1,8250142, 71,7445288, -1,8391156, 71,7305266, -1,79971
    27, 71,7277262, -1,6372994, 71,7680328, -1,8371151, 71,7477293, -1,7914116, 71,7
    485295, -2,5499818, 69,7686808, -3,7134102, 66,319762, -4,296207, 64,3409166, -4
    ,7468036, 62,8630039, -4,8797025, 62,2661018, -5,5455029, 59,897899, -5,9832082,
    58,4219931, -6,1319107, 58,0187899, -6,4952136, 57,9000878, -7,4540322, 56,5183
    651, -7,540535, 56,3235608, -6,3898286, 55,3796474, -6,1153258, 55,3534483, -5,1
    883214, 54,4165272, -5,9829533, 51,4761912, -6,0178661, 49,9881936, -5,2705573,
    48,5816924))
            SELECT ID,
                   sdo_util.simplify(
                                     GEOM,
                                     100000,0.05) SMPL_SHAPE
                  FROM TEST_SP A;             
             1
    SDO_GEOMETRY(2006, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(
    -4,4782378, 48,3825828, -7,5433349, 56,3382611, -3,3610006, 62,7598027, -5,9890247
    , 64,9128292, -2,4798621, 71,9148546, 4,54839096, 72,7997504, ,569477285, 71,82595
    , ,547178691, 73,1469855, 3,23637231, 71,518823, -,82198316, 72,9230354, 3,31881376
    , 72,5687954, -1,9711251, 71,75383, -7,540535, 56,3235608, -5,1883214, 54,4165272
    , -5,2705573, 48,5816924))              Which version of server and client do you use (database)?
    regards, Andreas

  • BGP decision algorithm nitty-gritty (relationship of locally originated routes to weight attribute)

    Hello everyone, i have a question on this algorithm. Specifically the relationship between (cisco specific) WEIGHT which is right at the top of the path selection algorithm.... and routes that are ORIGINATED_LOCALLY (3rd one down, after weight and local_pref). 
    Heres the relevant steps of the decision tree: 
       1/WEIGHT (highest wins)
       2/LOCAL_PREF (highest wins) 
       3/ORIGINATED LOCALLY (prefer locally originated over peer learnt) 
    Whats confusing to me is that Jeff's book tells us that if a prefix is ORIGINATED_LOCALLY (ie entered into BGP on that same router - either by a network/aggregate-address statement, or from redistribution) then its WEIGHT will also be set to 32768 (as opposed to a BGP peer learnt route whose WEIGHT is set to 0). I understand this. 
    My question is why??? Seems to me that if this is the case there is little purpose of having ORIGINATED_LOCALLY in the decision tree at all, as the logic will never get there on account of the the propagation of its value into (the higher up) WEIGHT decision. This also in turn means that ORIGINATED_LOCALLY has the power to override the attribute LOCAL_PREF.... so couldn't this whole logic be simplified to be: 
       1/WEIGHT or ORIGINATED LOCALLY
       2/LOCAL_PREF (highest wins) 
    This very thing has confused another user on another post too, that user writes:  "I tried thinking of an example where "ORIGINATED LOCALLY" works but weight doesn't, but couldn't think of any."
    looking forward to the thoughts of this community.
    Thanks in advance, Keiran. 
    PS> perhaps the attached diagram will help visualise this. 

    Thanks for your reply shaikhkamran123, i hadn't considered the multivendor environment (where cisco specific concept of 'weight' would be irrelevant to those routers), so yes their decision would start with: 
    1) Local Preference
    2) Locally originated
    as opposed to cisco
       1/WEIGHT (highest wins)
       2/LOCAL_PREF (highest wins) 
       3/ORIGINATED LOCALLY (prefer locally originated over peer learnt) 
    but it still doesn't really explain why cisco chose to alter their inbuilt weight based on if a route was locally originated. This alters the logic of the above decision algorithm: ie if its locally originated, it will set a high weight (32768), which will be preferred.... and heres the main thing *BEFORE* local_pref is even looked at.  So in other words decision criteria#3, gets merged into #1, skipping ahead of #2.  Am i going crazy here?? 
    thanks in advance all... 
    K. 

  • Logic Execution Algorithm - Help

    Help for me - Logic Execution Algorithm
    Considering the Execution Sequence 1: Consider the following information in the table GBI_PAR_DEFINE_ROTA parameterized.
    The required fields are filled in by users: Required_Res_1 and one of the fields:
    Product_id, customer_id or Sales_Order_No.
    Off the field will only be filled with the value N if you want to disable the rule. If the value of the rule is N, the routine being developed disregard the rule.
    REQUIRED_RES_1 PRODUCT_ID SALES_ORDER_NO CUSTOMER_ID OFF
    P_P_LAM2 P_289874 18669437-20 WHGA
    Step 1: Find Table MP_WO_REP which records have sales order number 18669437-20.
    Step 2: Within these sales orders, search through the table Works_Operation which ones have the field Product_ID = P_289874.
    Step 3: Restrict further data selection Sales_Order searching the table, which of them belong to the client WHGA.
    Step 4: In the records remaining in the table Works_Operation verify which code Alternate_Pref whose field Required_Res_1 equals P_P_LAM2. If more than one return Alternate_Pref (different) for the same product_id Required_Res_1 and generate a table of error called GBI_ERR_ALTERNATE_PREF, containing the following information: Required_Res_1, Works_Order and product_id. If this error occurs, the following steps should not be performed.
    Step 5: In the remaining records, delete those records whose field Alternate_Pref is different from the value returned in Step 4. IMPORTANT NOTE: The records can only be deleted if they exist for the same product_id Alternates_Prefs different. These same deleted records should be inserted in the table Works_Operation_Rota_Excluida.
    Step 6: Deleted records Works_Operation table must also be deleted from the table Works_Op_Char. Fields of connection between these two tables are: Works_Order_No, Version_No, Works_Op_No, Alternate_Pref and Op_Proc_No. Deleted records will be recorded in the table Works_OP_Char_Rota_Excluida.

    I did not offer an opinion.
    You have what is called a technical or program specification. It describes the programming steps that need to be designed and written. This is exactly what programmers do. And your seeming inability to do this, points to the fact that you are not a programmer. That is the issue you need to address - instead of looking for so-called algorithmic logic.
    Simple and basic approach. Take step 1. Write SQL code that satisfies the requirements and outputs of that step. E.g.
    Step 1: Find Table MP_WO_REP which records have sales order number 18669437-20.
    Code: select * from mp_wo_rep where sales_order = '18669437-20'
    Do the same for step 2. And the remaining steps
    You now have the basic code template required to perform these steps. The next actions are:
    Modularising the code (instead of a hardcoded sales order number, support specifying it as a parameter).
    Simplify the code (by combining and integrating processing steps). Real programming is said to be the act of removing program source code statements, and not writing them.

  • Pixel "selection" algorithm

    I am trying to write an algorithm that operates on a 2-bit (Black and white) image. Given a black pixel, it needs to be able to find all other black pixels that are directly connected to it, or indirectly connected to it (connected to it by being connected to another pixel that is directly connected to it, however many levels deep). (If you have ever used photoshop before, I am basically refering to the idea of a very simplified magic wand selection tool) I currently have this method implemented recursively, it traverses through the pixels as though they were a tree structure, which works for smaller images, but for larger images (longer paths to traverse) it gets a stack overflow. Does anyone know of any algorithms that would preform this kind of a task?

    It is fairly easy to convert a recursive "connected-components" algorithm to an iterative one. You just have to maintain your own stack (Use one of the List implementations in java.util)
    Remember that the pathological case for a recursive connected components algorithm results in the depth of recursion equaling the number of pixels in the image.
    matfud

  • Simplifying Complex Polygons

    Hi all,
    I need to simplify a coverage data by removing the number of vertices for speeding up the analysis..I understand teh sdo_util.simplify will help us to acheive this.Can someone help me how to go about this.Do i need to write PL/sql to acheive this , can anyone post any examples how they simplify the complex polygons.
    And what is teh difference between teh wrapper(sdo_sam.simplify_geometry) and sdo_util.simplify?
    Thank you very much.

    Hi,
    sdo_util.simplify uses the Douglas-Peuker algorithm to simplify geometry. It is the algorithm used by most GIS to achieve this as it removes vertices whilst retaining shape.
    You do not need to use PL/SQL as you can do using SQL.
    I have done some experiments with simplify to achieve greater performance in an application. It uses the same algorithm but uses a 3rd party package.
    I used
    CREATE TABLE SIMPLIFIED AS
    SELECT fz_id, sdo_util.simplify(c.geom, 1) simplified, c.geom
    FROM nfcdd_owner_flood_zone_3_fluv1 c
    in my tests.
    Ivan

  • Best Algorithm and how to start

    Hi All,
    I am a new user of Oracle Data Mining. I have a database of customers with their records who bought good from our shop.
    Now i want to predict the probability of new customers buying goods from our shop. The new customers may/may not be the old customers.
    I need to show these information in JSF.
    SO can anyone please give any pointers so as to how to start building the application.
    Which algorithm is the best with most accuracy.
    Thanks in advance,
    Anshu Gupta

    Whether you are new to data mining in general or just new to Oracle Data Mining, I recommend that your read the materials on the Getting Started w/ ODM pages http://www.oracle.com/technology/products/bi/odm/odm_education.html.
    The ODM Tutorial http://download.oracle.com/odm/odminer/tutorial/11.1/Oracle-Data-Miner-11g-Tutorial.zip is highly instructional w/ examples. Following along w/ the Tutorial and its demo data never hurts and will help answer many basic and advanced dm questions by using the product.
    After that, thinking about getting the right data for any of the ODM algorithms to find the patterns and relationships hidden within is the main challenge. In the new 11gR2 GUI, we automatically ruin 4 classification models (i of each flavor w/ default settings). You can add more and/or adjust algorithm parameters. In 10gR2 and 11gR1 "Classic" ODM'r GUI,after you have thought about how to set up the problem and have gathered/assembled the right data for the problem, just quickly build several different models and compare them. We've done a lot of work to automate and simplify the dm process so that by just using the ODM defaults, any algorithm should provide a reasonably good model. Experts might be able to adjust, tune, change algorithms, etc., but you should get good results regardless.
    Good luck!
    cb

  • Describing algorithms (xml)

    Heya guys (and girls :p),
    I need some help here. I am about to start a new project and I'm kinda at a loss on what to do.
    The idea is to create a site where I can fill in a questionair (a webforms thus). The forms are created by using different kind of XML files. One kind of XML file describes the form fields (the questions), another describes the algorithms behind the questions. With the algorithms I should be able to process the answers on my questions and do statistical calculations.
    The creation of forms doesn't really look like it's going to be a problem, but the algorithms are... How can I solve the issue on having an XML file describing things like 'if x>100 && z <= y do this...' and making the link to Java alike code. I don't really fancy writing an analyzer from scratch (although if it needs to be done so shall it be :p). Are there any description languages available who can solve this prob? Java classes? At the moment I'm thinking of using the Struts framework with XForms, Jakatra BCEL (code generator), some database stuff and probably some Beans along the path. Any input/ suggestions /technologies would put yall on my hall of fame :p
    Thnx in advance
    Jurgen

    The following Business Rule Solution uses POJO's and XML and meets the following criteria!
    Business Rule Solutions should be:
    Non-Industry Specific
    Appropriate and Affordable for any size business
    Enterprise-class solution (scalable, optimized, extensible)
    Remember: All businesses have business rules, and all businesses need an efficient way of managing and executing these business rules.
    What Business Rule Solutions should provide:
    Input Validation & Data Integrity
    Integration & Data Transformation
    Analytics
    Interpret clients Business Policies & Behaviors and clients run-time
    data and execute the appropriate process related workflow efficiently.
    The Return on Investment:
    ROI continues every day, week, month and year into the future!
    Simplify all program development through component reuse.
    Lowers software maintenance by a magnitude.
    Manages & Protects a company assets (Business Rules) in one
    repository.
    Provide Business Agility and Competitive Advantage!
    Further, I believe Business Rule Solutions are a higher level of abstraction of services that all other applications should use to implement the Model-View-Controller design pattern!
    Run the Demo!
    Use the Contact Us! page for quicker responses. http://www.agilebusinessrulecomponents.com

Maybe you are looking for

  • My iPhone4 doesn't want to charge or turn on

    Last week my phone suddenly turned off when I took it off the charger. I had to shake it so it can turn, sometimes it doesn't even turn on. It doesn't charge fully, it usually stops at 40% and it usually only stays on when it's plugged in a charger.

  • Hyper-v Failover clustering for SQL Server lab

    Hi, After 20yrs years of IT software experience, now I am realizing that I don't know much about hyperV clustering. :) I am trying to setup a lab. I badly need help on configuring network adapters to make the machines accessible from each other. Plea

  • Photoshop CS2 quits

    App quits when I doubleclick to open. I talked to a tech at Adobe and he says it's a corrupt system font, Arial. How do I get rid of this problem. I'm leery about trashing a system font.

  • Copying text to WIndows clipboard

    I have a JTextPane and want to be be to cut & paste text from it to Windows ckipboard so I can paste into Windows. So if I select text displayed in 12 point Arial, I will get the Text in Word from a paste but not the style. I can cut and paste the te

  • User names in MAC OS

    I'm confused by how user names work in OS X, specifically when it comes to screen sharing. I have two Macs with the same user name and password on both (for example, account name "Jonathan Doe"). When I log into either computer, the full user name is