示例#1
0
void PrintOps(PhysicalOp_t *phyOp, int ind){
    if(!phyOp) return;
    
    for(int i=0; i<ind; i++)
        cout<<"| ";
    phyOp->PrintName();
    cout<<endl;    
    int n = phyOp->NumInputs();

    for( int i = 0 ; i < n ; i++ ) {
        const PlanGroup_t *inpPG = phyOp->ActualInput(i);
        if( !inpPG ) 
            inpPG = phyOp->Input(i);
        assert(inpPG);

        Plan_t *inpPlan = inpPG->BestPlan();
        if( !inpPlan )
            inpPlan = inpPG->BestAlgPlan();
        else if( inpPlan->IsFailed() )
            inpPlan = inpPG->BestAlgPlan();
        assert(inpPlan);
        assert(!inpPlan->IsFailed());
        
        PrintOps(inpPlan->Root(), ind+1);
        //inpPlan->PrintPlan(indentLevel+1);
    }
    
}
示例#2
0
void printEditDist(char x[], char y[])
{
    int m, n;
    int * cost, *ops;
    int cost_for_right_or_replace;
    int cost_for_insert;
    int cost_for_delete;
    int min;
    int i, j;
    int opDone;

    m = strlen(x);
    n = strlen(y);
    cost = (int *) malloc((m+1) * (n+1) * sizeof(int));
    assert(cost != NULL);
    ops = (int *) malloc((m+1) * (n+1) * sizeof(int));
    assert(ops != NULL);
    for (i = 0; i <= m; i++) {
        for (j = 0; j <= n; j++) {
            cost_for_right_or_replace = cost_for_delete = cost_for_insert = INT_MAX;
            if (i > 0 && j > 0) {
                if (x[i-1] == y[j-1])
                    cost_for_right_or_replace = cost[(i-1)*(n+1)+j-1] + RIGHT_COST;
                else {
                    cost_for_right_or_replace = cost[(i-1)*(n+1)+j-1] + REPLACE_COST;
                }
            }
            if (i > 0) {
                cost_for_delete = cost[(i-1)*(n+1)+j] + DELETE_COST;
            }
            if (j > 0) {
                cost_for_insert = cost[i*(n+1)+j-1] + INSERT_COST;
            }
            min = cost_for_right_or_replace;
            if (x[i-1] == y[j-1])
                opDone = RIGHT;
            else
                opDone = REPLACE;
            if (min > cost_for_delete) {
                min = cost_for_delete;
                opDone = DELETE;
            }
            if (min > cost_for_insert) {
                min = cost_for_insert;
                opDone = INSERT;
            }
            if (i == 0 && j == 0)
                min = 0;
            cost[i*(n+1)+j] = min;
            ops[i*(n+1)+j] = opDone;
        }
    }
    printf("x: %s\n", x);
    printf("y: %s\n", y);
    printf("Edit Distance: %d\n", cost[m*(n+1)+n]);
    printf("\n");
    PrintOps(ops, x, m, y, n, m, n, cost);
    free(ops);
    free(cost);
}
示例#3
0
/* PrintOps: print operations performed on string x. The first call is
 * PrintOps(ops, x, m, y, n, m, n, cost)
 */
void PrintOps(int *ops, char x[], int m, char y[], int n, int i, int j, int *cost)
{
    int k;

    assert(ops != NULL && cost != NULL);
    if (i >= 1 || j >= 1)
        switch (ops[i*(n+1)+j]) {
        case RIGHT:
            PrintOps(ops, x, m, y, n, i-1, j-1, cost);
            printf("%-8s| %d | %3d | ",
                   "Right", 0, cost[i*(n+1)+j]);
            break;
        case INSERT:
            PrintOps(ops, x, m, y, n, i, j-1, cost);
            printf("%-8s| %d | %3d | ",
                   "Insert", 3, cost[i*(n+1)+j]);
            break;
        case REPLACE:
            PrintOps(ops, x, m, y, n, i-1, j-1, cost);
            printf("%-8s| %d | %3d | ",
                   "Replace", 4, cost[i*(n+1)+j]);
            break;
        case DELETE:
            PrintOps(ops, x, m, y, n, i-1, j, cost);
            printf("%-8s| %d | %3d | ",
                   "Delete", 2, cost[i*(n+1)+j]);
            break;
        }
    else {
        printf("%-8s| c |Total| z\n", "Oper");
        printf("----------------------------------\n");
        printf("%-8s| %d | %3d | ",
               "Initial", 0, 0);
    }
    for (k = 0; k < j; k++)
        printf("%c", y[k]);
    printf("*");
    for (k = i; k < m; k++)
        printf("%c", x[k]);
    printf("\n");
}
示例#4
0
void eval(Plan_t *plan){
    PhysicalOp_t * root = plan->Root();
    
    cout<<"\nPhysical Operator tree:\n\n";
    PrintOps(root,0 );
    cout<<endl<<endl;
    
//Mubase initialisation

    cout << "\n STARTING MUBASE\n";

    DiskManager::createDB("mydb.txt", 20);
    StorageManager::initDB("mydb.txt");
    DiskManager::openDB("mydb.txt");

    //Create Relations
    cout << "\nCreating Relations\n";
    const short int numAttrs1 = 4;
    short int attrType1[numAttrs1] = {1, 4, 4, 2};
    short int sizeAttrs1[numAttrs1] = {sizeof(int), 30, 30, sizeof(float)};
    char *attrName1[numAttrs1] = {"r1c1", "r1c2", "r1c3", "r1c4"}; //Column Names for relation r1
    Schema sch1(numAttrs1, attrType1, attrName1, sizeAttrs1);
    Relation r1("mydb.txt", "r1", true, &sch1);

    const short int numAttrs2 = 3;
    short int attrType2[numAttrs2] = {1, 4, 1};
    short int sizeAttrs2[numAttrs2] = {sizeof(int), 30, sizeof(int)};
    char* attrName2[numAttrs2] = {"r2c1", "r2c2", "r2c3"};  //Column Names for relation r2
    Schema sch2(numAttrs2, attrType2, attrName2, sizeAttrs2);
    Relation r2("mydb.txt", "r2", true, &sch2);
    
    const short int numAttrs3 = 2;
    short int attrType3[numAttrs3] = {1, 4};
    short int sizeAttrs3[numAttrs3] = { sizeof(int), 30};
    char* attrName3[numAttrs3] = {"r3c1", "r3c2"};  //Column Names for relation r3
    Schema sch3(numAttrs3, attrType3, attrName3, sizeAttrs3);
    Relation r3("mydb.txt", "r3", true, &sch3);
    
    
    
    //creating records
    string recString1[numAttrs1] = {"29", "sachin", "rathod", "11.11"};
    Record* recp1 = new Record(recString1, &sch1, numAttrs1);
    string recString2[numAttrs1] = {"09", "aniket", "deshmukh", "22.22"};
    Record* recp2 = new Record(recString2, &sch1, numAttrs1);
    
    string recString3[numAttrs2] = {"08", "chirag", "33"};
    Record* recp3 = new Record(recString3, &sch2, numAttrs2);
    string recString4[numAttrs2] = {"17", "manish", "44"};
    Record* recp4 = new Record(recString4, &sch2, numAttrs2);
    
    string recString5[numAttrs3] = { "431122", "beed"};
    Record* recp5 = new Record(recString5, &sch3, numAttrs3);
    string recString6[numAttrs3] = { "411004", "pune"};
    Record* recp6 = new Record(recString6, &sch3, numAttrs3);
    string recString7[numAttrs3] = { "431100", "abad"};
    Record* recp7 = new Record(recString7, &sch3, numAttrs3);
    
    //adding records to relations
    r1.addRecord(*recp1);
    //for (int i = 0; i < 10; i++) r1.addRecord(*recp1);
    r1.addRecord(*recp2);
    r1.addRecord(*recp2);
    r1.addRecord(*recp2);

    r2.addRecord(*recp3);
    r2.addRecord(*recp4);
    r2.addRecord(*recp3);
    r2.addRecord(*recp3);
    r2.addRecord(*recp4);
    
    r3.addRecord(*recp5);
    r3.addRecord(*recp6);
    r3.addRecord(*recp7);
    

//End- Mubase initialisation
    
    //Evaluation
    cout<<"\nQuery Result:\n\n";
    int rno = 1;
    root->open();
    Record* rec;
    
    rec = root->next();
    while(rec){
        cout<<"Record["<<rno<<"]: ";
        rec->print();
        rec = root->next();
        rno++;
    }
    
    root->close();
    //End Evaluation
    
//close Mubase db
    DiskManager::closeDB("mydb.txt");    
    cout << "\nTHE END\n";
}
示例#5
0
void printEditDist(const char x[], const char y[])
{
    int m, n;
    int * cost, *ops;
    int cost_for_delete, cost_for_insert, cost_for_replace;
    int i, j;

    m = strlen(x);
    n = strlen(y);
    cost = (int *) malloc((m+1) * (n+1) * sizeof(int));
    assert(cost != NULL);
    ops = (int *) malloc((m+1)*(n+1)*sizeof(int));
    assert(ops != NULL);

    cost[m*(n+1)+n] = 0;
    for (i = m, j = n-1; j >= 0; j--) {
        ops[i*(n+1)+j] = INSERT;
        cost[i*(n+1)+j] = cost[i*(n+1)+j+1] + INSERT_COST;
    }
    for (j = n, i = m-1; i >= 0; i--) {
        cost[i*(n+1)+j] = cost[(i+1)*(n+1)+j] + DELETE_COST;
        ops[i*(n+1)+j] = DELETE;
    }

    for (i = m-1; i >= 0; i--) {
        for (j = n-1; j >= 0; j--) {
            if (x[i] == y[j]) {
                cost[i*(n+1)+j] = cost[(i+1)*(n+1)+j+1] + RIGHT_COST;
                ops[i*(n+1)+j] = RIGHT;
            } else {
                cost_for_delete = cost[(i+1)*(n+1)+j] + DELETE_COST;
                cost_for_insert = cost[i*(n+1)+j+1] + INSERT_COST;
                cost_for_replace = cost[(i+1)*(n+1)+j+1] + REPLACE_COST;
                if (cost_for_delete < cost_for_insert) {
                    if (cost_for_delete < cost_for_replace) {
                        cost[i*(n+1)+j] = cost_for_delete;
                        ops[i*(n+1)+j] = DELETE;
                    } else {
                        cost[i*(n+1)+j] = cost_for_replace;
                        ops[i*(n+1)+j] = REPLACE;
                    }
                } else {
                    if (cost_for_insert < cost_for_replace) {
                        cost[i*(n+1)+j] = cost_for_insert;
                        ops[i*(n+1)+j] = INSERT;
                    } else {
                        cost[i*(n+1)+j] = cost_for_replace;
                        ops[i*(n+1)+j] = REPLACE;
                    }
                }
            }
        }
    }
    printf("x: %s\n", x);
    printf("y: %s\n", y);
    printf("Edit Distance: %d\n", cost[0]);
    printf("\n");
    PrintOps(ops, x, y);
    free(ops);
    free(cost);
}