From: adash Date: Tue, 16 Jun 2009 00:10:02 +0000 (+0000) Subject: clean up code X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=97713f87247ff7d68692ed577ac4c547582f355f;p=IRC.git clean up code bug fix for sorting --- diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java b/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java index 220f18fb..24be2441 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java @@ -6,6 +6,8 @@ * * Copyright (C) Stanford University, 2006. All Rights Reserved. * Author: Chi Cao Minh + * Ported to Java June 2009 Alokika Dash + * University of California, Irvine * * ============================================================================= * @@ -75,15 +77,6 @@ * * ============================================================================= */ - /* -#include -#include -#include "adtree.h" -#include "data.h" -#include "query.h" -#include "utility.h" -#include "vector.h" -*/ public class Adtree { int numVar; @@ -103,7 +96,6 @@ public class Adtree { { nodePtr.varyVectorPtr.vector_free(); nodePtr = null; - //free(nodePtr); } @@ -116,7 +108,6 @@ public class Adtree { freeVary (AdtreeVary varyPtr) { varyPtr = null; - //free(varyPtr); } @@ -127,8 +118,6 @@ public class Adtree { public static Adtree adtree_alloc () { Adtree adtreePtr = new Adtree(); - //adtree_t* adtreePtr; - //adtreePtr = (adtree_t*)malloc(sizeof(adtree_t)); if (adtreePtr != null) { adtreePtr.numVar = -1; adtreePtr.numRecord = -1; @@ -148,12 +137,9 @@ public class Adtree { { if (nodePtr != null) { Vector_t varyVectorPtr = nodePtr.varyVectorPtr; - //vector_t* varyVectorPtr = nodePtr.varyVectorPtr; - //int v; int numVary = varyVectorPtr.vector_getSize(); for (int v = 0; v < numVary; v++) { AdtreeVary varyPtr = (AdtreeVary)(varyVectorPtr.vector_at(v)); - //adtree_vary_t* varyPtr = (adtree_vary_t*)vector_at(varyVectorPtr, v); freeNodes(varyPtr.zeroNodePtr); freeNodes(varyPtr.oneNodePtr); freeVary(varyPtr); @@ -171,28 +157,8 @@ public class Adtree { adtree_free () { freeNodes(rootNodePtr); - this = null; - //free(adtreePtr); } - - /* - static adtree_vary_t* - makeVary (int parentIndex, - int index, - int start, - int numRecord, - Data* dataPtr); - - static adtree_node_t* - makeNode (int parentIndex, - int index, - int start, - int numRecord, - Data* dataPtr); - */ - - /* ============================================================================= * makeVary * ============================================================================= @@ -205,7 +171,6 @@ public class Adtree { Data dataPtr) { AdtreeVary varyPtr = AdtreeVary.allocVary(index); - //assert(varyPtr); if ((parentIndex + 1 != index) && (numRecord > 1)) { dataPtr.data_sort(start, numRecord, index); @@ -249,28 +214,20 @@ public class Adtree { Data dataPtr) { AdtreeNode nodePtr = AdtreeNode.allocNode(index); - //adtree_node_t* nodePtr = allocNode(index); - //assert(nodePtr); nodePtr.count = numRecord; Vector_t varyVectorPtr = nodePtr.varyVectorPtr; - //vector_t* varyVectorPtr = nodePtr.varyVectorPtr; - - //int v; int numVar = dataPtr.numVar; for (int v = (index + 1); v < numVar; v++) { AdtreeVary varyPtr = - //adtree_vary_t* varyPtr = makeVary(parentIndex, v, start, numRecord, dataPtr); - //assert(varyPtr); boolean status; if((status = varyVectorPtr.vector_pushBack(varyPtr)) != true) { System.out.println("varyVectorPtr.vector_pushBack != true"); System.exit(0); } - //assert(status); } return nodePtr; @@ -317,7 +274,6 @@ public class Adtree { Query queryPtr = (Query)(queryVectorPtr.vector_at(q)); - //query_t* queryPtr = (query_t*)vector_at(queryVectorPtr, q); if (queryPtr != null) { return nodePtr.count; } @@ -326,14 +282,9 @@ public class Adtree { System.out.println("Assert failed"); System.exit(0); } - //assert(queryIndex <= lastQueryIndex); + Vector_t varyVectorPtr = nodePtr.varyVectorPtr; - //vector_t* varyVectorPtr = nodePtr.varyVectorPtr; AdtreeVary varyPtr = (AdtreeVary)(varyVectorPtr.vector_at((queryIndex - nodeIndex - 1))); - //adtree_vary_t* varyPtr = - // (adtree_vary_t*)vector_at(varyVectorPtr, - // (queryIndex - nodeIndex - 1)); - //assert(varyPtr); int queryValue = queryPtr.value; @@ -347,21 +298,16 @@ public class Adtree { */ int numQuery = queryVectorPtr.vector_getSize(); Vector_t superQueryVectorPtr = Vector_t.vector_alloc(numQuery - 1); - //vector_t* superQueryVectorPtr = PVECTOR_ALLOC(numQuery - 1); //MEMORY ALLOACATED FROM THREAD POOL - //assert(superQueryVectorPtr); - //int qq; for (int qq = 0; qq < numQuery; qq++) { if (qq != q) { boolean status = superQueryVectorPtr.vector_pushBack( queryVectorPtr.vector_at(qq)); - //assert(status); } } int superCount = adtree_getCount(superQueryVectorPtr); superQueryVectorPtr.vector_free(); - //PVECTOR_FREE(superQueryVectorPtr); int invertCount; if (queryValue == 0) { @@ -398,23 +344,8 @@ public class Adtree { queryVectorPtr, lastQueryIndex); } else { /* QUERY_VALUE_WILDCARD */ - /* -#if 0 - count += getCount(varyPtr.zeroNodePtr, - (i + 1), - (q + 1), - queryVectorPtr, - lastQueryIndex); - count += getCount(varyPtr.oneNodePtr, - (i + 1), - (q + 1), - queryVectorPtr, - lastQueryIndex, - adtreePtr); -#else - assert(0); // catch bugs in learner -#endif - */ + System.out.println("Program shouldn't get here"); // catch bugs in learner + System.exit(0); } } @@ -431,7 +362,6 @@ public class Adtree { public int adtree_getCount (Vector_t queryVectorPtr) { - //AdtreeNode rootNodePtr = adtreePtr.rootNodePtr; if (rootNodePtr == null) { return 0; } @@ -440,7 +370,6 @@ public class Adtree { int numQuery = queryVectorPtr.vector_getSize(); if (numQuery > 0) { Query lastQueryPtr = (Query)(queryVectorPtr.vector_at(numQuery - 1)); - //query_t* lastQueryPtr = (query_t*)vector_at(queryVectorPtr, (numQuery - 1)); lastQueryIndex = lastQueryPtr.index; } @@ -450,251 +379,10 @@ public class Adtree { queryVectorPtr, lastQueryIndex); } - - - /* ############################################################################# - * TEST_ADTREE - * ############################################################################# - */ - /* -#ifdef TEST_ADTREE - -#include -#include "timer.h" - - static void printNode (adtree_node_t* nodePtr); - static void printVary (adtree_vary_t* varyPtr); - - boolean global_doPrint = FALSE; - - - static void - printData (Data* dataPtr) - { - int numVar = dataPtr.numVar; - int numRecord = dataPtr.numRecord; - - int r; - for (r = 0; r < numRecord; r++) { - printf("%4li: ", r); - char* record = data_getRecord(dataPtr, r); - assert(record); - int v; - for (v = 0; v < numVar; v++) { - printf("%li", (int)record[v]); - } - puts(""); - } - } - - - static void - printNode (adtree_node_t* nodePtr) - { - if (nodePtr) { - printf("[node] index=%li value=%li count=%li\n", - nodePtr.index, nodePtr.value, nodePtr.count); - vector_t* varyVectorPtr = nodePtr.varyVectorPtr; - int v; - int numVary = vector_getSize(varyVectorPtr); - for (v = 0; v < numVary; v++) { - adtree_vary_t* varyPtr = (adtree_vary_t*)vector_at(varyVectorPtr, v); - printVary(varyPtr); - } - } - puts("[up]"); - } - - - static void - printVary (adtree_vary_t* varyPtr) - { - if (varyPtr) { - printf("[vary] index=%li\n", varyPtr.index); - printNode(varyPtr.zeroNodePtr); - printNode(varyPtr.oneNodePtr); - } - puts("[up]"); - } - - - static void - printAdtree (adtree_t* adtreePtr) - { - printNode(adtreePtr.rootNodePtr); - } - - - static void - printQuery (vector_t* queryVectorPtr) - { - printf("["); - int q; - int numQuery = vector_getSize(queryVectorPtr); - for (q = 0; q < numQuery; q++) { - query_t* queryPtr = (query_t*)vector_at(queryVectorPtr, q); - printf("%li:%li ", queryPtr.index, queryPtr.value); - } - printf("]"); - } - - - static int - countData (Data* dataPtr, vector_t* queryVectorPtr) - { - int count = 0; - int numQuery = vector_getSize(queryVectorPtr); - - int r; - int numRecord = dataPtr.numRecord; - for (r = 0; r < numRecord; r++) { - char* record = data_getRecord(dataPtr, r); - boolean isMatch = TRUE; - int q; - for (q = 0; q < numQuery; q++) { - query_t* queryPtr = (query_t*)vector_at(queryVectorPtr, q); - int queryValue = queryPtr.value; - if ((queryValue != QUERY_VALUE_WILDCARD) && - ((char)queryValue) != record[queryPtr.index]) - { - isMatch = FALSE; - break; - } - } - if (isMatch) { - count++; - } - } - - return count; - } - - - static void - testCount (adtree_t* adtreePtr, - Data* dataPtr, - vector_t* queryVectorPtr, - int index, - int numVar) - { - if (index >= numVar) { - return; - } - - int count1 = adtree_getCount(adtreePtr, queryVectorPtr); - int count2 = countData(dataPtr, queryVectorPtr); - if (global_doPrint) { - printQuery(queryVectorPtr); - printf(" count1=%li count2=%li\n", count1, count2); - fflush(stdout); - } - assert(count1 == count2); - - query_t query; - - int i; - for (i = 1; i < numVar; i++) { - query.index = index + i; - boolean status = vector_pushBack(queryVectorPtr, (void*)&query); - assert(status); - - query.value = 0; - testCount(adtreePtr, dataPtr, queryVectorPtr, query.index, numVar); - - query.value = 1; - testCount(adtreePtr, dataPtr, queryVectorPtr, query.index, numVar); - - vector_popBack(queryVectorPtr); - } - } - - - static void - testCounts (adtree_t* adtreePtr, Data* dataPtr) - { - int numVar = dataPtr.numVar; - vector_t* queryVectorPtr = vector_alloc(numVar); - int v; - for (v = -1; v < numVar; v++) { - testCount(adtreePtr, dataPtr, queryVectorPtr, v, dataPtr.numVar); - } - vector_free(queryVectorPtr); - } - - - static void - test (int numVar, int numRecord) - { - random_t* randomPtr = random_alloc(); - Data* dataPtr = data_alloc(numVar, numRecord, randomPtr); - assert(dataPtr); - data_generate(dataPtr, 0, 10, 10); - if (global_doPrint) { - printData(dataPtr); - } - - Data* copyDataPtr = data_alloc(numVar, numRecord, randomPtr); - assert(copyDataPtr); - data_copy(copyDataPtr, dataPtr); - - adtree_t* adtreePtr = adtree_alloc(); - assert(adtreePtr); - - TIMER_T start; - TIMER_READ(start); - - adtree_make(adtreePtr, copyDataPtr); - - TIMER_T stop; - TIMER_READ(stop); - - printf("%lf\n", TIMER_DIFF_SECONDS(start, stop)); - - if (global_doPrint) { - printAdtree(adtreePtr); - } - - testCounts(adtreePtr, dataPtr); - - adtree_free(adtreePtr); - random_free(randomPtr); - data_free(dataPtr); - } - - - int - main () - { - puts("Starting..."); - - puts("Test 1:"); - test(3, 8); - - puts("Test 2:"); - test(4, 64); - - puts("Test 3:"); - test(8, 256); - - puts("Test 4:"); - test(12, 256); - - puts("Test 5:"); - test(48, 1024); - - puts("All tests passed."); - - return 0; - } - - -#endif // TEST_ADTREE - */ - } /* ============================================================================= * - * End of adtree.c + * End of adtree.java * * ============================================================================= */ diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeNode.java b/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeNode.java index 3092fc14..e3322077 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeNode.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeNode.java @@ -1,3 +1,10 @@ +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Helper class of Adtree.java + **/ public class AdtreeNode { int index; int value; @@ -16,15 +23,11 @@ public class AdtreeNode { allocNode (int index) { AdtreeNode nodePtr = new AdtreeNode(); - //adtree_node_t* nodePtr; - //nodePtr = (adtree_node_t*)malloc(sizeof(adtree_node_t)); if (nodePtr != null) { - //nodePtr.varyVectorPtr = vector_alloc(1); nodePtr.varyVectorPtr = Vector_t.vector_alloc(1); if (nodePtr.varyVectorPtr == null) { nodePtr = null; - //free(nodePtr); return null; } nodePtr.index = index; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeVary.java b/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeVary.java index f4bbfe46..e7c24925 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeVary.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/AdtreeVary.java @@ -1,3 +1,11 @@ +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Helper class of Adtree.java + **/ + public class AdtreeVary { int index; int mostCommonValue; @@ -16,9 +24,7 @@ public class AdtreeVary { allocVary (int index) { AdtreeVary varyPtr= new AdtreeVary(); - //adtree_vary_t* varyPtr; - //varyPtr = (adtree_vary_t*)malloc(sizeof(adtree_vary_t)); if (varyPtr != null) { varyPtr.index = index; varyPtr.mostCommonValue = -1; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java b/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java index 713b310c..4f38d3d8 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java @@ -6,8 +6,8 @@ * * Copyright (C) Stanford University, 2006. All Rights Reserved. * Author: Chi Cao Minh - * Ported to Java - * Author: Alokika Dash + * Ported to Java June 2009 Alokika Dash + * University of California, Irvine * * ============================================================================= * @@ -210,8 +210,6 @@ public class Bayes extends Thread { Learner learnerPtr = Learner.learner_alloc(dataPtr, adtreePtr, 1); - //learner_t* learnerPtr = learner_alloc(dataPtr, adtreePtr, 1); - Net tmpNetPtr = learnerPtr.netPtr; learnerPtr.netPtr = netPtr; @@ -256,71 +254,47 @@ public class Bayes extends Thread { int percentParent = b.global_params[PARAM_PERCENT]; b.global_insertPenalty = b.global_params[PARAM_INSERT]; b.global_maxNumEdgeLearned = b.global_params[PARAM_EDGE]; - //SIM_GET_NUM_CPU(numThread); - //TM_STARTUP(numThread); - //P_MEMORY_STARTUP(numThread); /* Initiate Barriers */ - //Barrier.setBarrier(numThread); + Barrier.setBarrier(numThread); Bayes[] binit = new Bayes[numThread]; - System.out.println("Random seed \n" + randomSeed); - System.out.println("Number of vars \n" + numVar); - System.out.println("Number of records \n" + numRecord); - System.out.println("Max num parents \n" + maxNumParent); - System.out.println("%% chance of parent \n" + percentParent); - System.out.println("Insert penalty \n" + b.global_insertPenalty); - System.out.println("Max num edge learned / var \n" + b.global_maxNumEdgeLearned); - System.out.println("Operation quality factor \n" + b.global_operationQualityFactor); + System.out.println("Random seed " + randomSeed); + System.out.println("Number of vars " + numVar); + System.out.println("Number of records " + numRecord); + System.out.println("Max num parents " + maxNumParent); + System.out.println("%% chance of parent " + percentParent); + System.out.println("Insert penalty " + b.global_insertPenalty); + System.out.println("Max num edge learned / var " + b.global_maxNumEdgeLearned); + System.out.println("Operation quality factor " + b.global_operationQualityFactor); /* * Generate data */ - System.out.println("Generating data... "); + System.out.print("Generating data... "); Random randomPtr = new Random(); randomPtr.random_alloc(); randomPtr.random_seed(randomSeed); - //random_t* randomPtr = random_alloc(); - //assert(randomPtr); - //random_seed(randomPtr, randomSeed); Data dataPtr = Data.data_alloc(numVar, numRecord, randomPtr); - //Data* dataPtr = data_alloc(numVar, numRecord, randomPtr); - //assert(dataPtr); Net netPtr = dataPtr.data_generate(-1, maxNumParent, percentParent); - //Net* netPtr = data_generate(dataPtr, -1, maxNumParent, percentParent); System.out.println("done."); - //puts("done."); - //fflush(stdout); /* * Generate adtree */ Adtree adtreePtr = Adtree.adtree_alloc(); - //adtree_t* adtreePtr = adtree_alloc(); - //assert(adtreePtr); - - System.out.println("Generating adtree... "); - //fflush(stdout); - //TIMER_T adtreeStartTime; - //TIMER_READ(adtreeStartTime); + System.out.print("Generating adtree... "); adtreePtr.adtree_make(dataPtr); - //TIMER_T adtreeStopTime; - //TIMER_READ(adtreeStopTime); - System.out.println("done."); - //fflush(stdout); - //System.out.println("Adtree time = %f\n", - // TIMER_DIFF_SECONDS(adtreeStartTime, adtreeStopTime)); - //fflush(stdout); /* * Score original network @@ -333,14 +307,11 @@ public class Bayes extends Thread { * Learn structure of Bayesian network */ - //START FROM HERE Learner learnerPtr = Learner.learner_alloc(dataPtr, adtreePtr, numThread); - //learner_t* learnerPtr = learner_alloc(dataPtr, adtreePtr, numThread); - //assert(learnerPtr); + dataPtr.data_free(); /* save memory */ - System.out.println("Learning structure..."); - //fflush(stdout); + System.out.print("Learning structure..."); /* Create and Start Threads */ for(int i = 1; i= 0) { randomPtr.random_seed(seed); } @@ -120,9 +114,7 @@ public class Data { * Generate random Bayesian network */ - //int numVar = dataPtr.numVar; Net netPtr = Net.net_alloc(numVar); - //assert(netPtr); netPtr.net_generateRandomEdges(maxNumParent, percentParent, randomPtr); /* @@ -130,20 +122,12 @@ public class Data { * value instances */ - //int** thresholdsTable = (int**)malloc(numVar * sizeof(int*)); - //int[][] thresholdsTable = new int[numVar][numThreshold]; - int[][] thresholdsTable = new int[numVar][]; - //assert(thresholdsTable); + int[][] thresholdsTable = new int[numVar][]; //TODO check if this is alright int v; for (v = 0; v < numVar; v++) { - //list_t* parentIdListPtr = Net.net_getParentIdListPtr(netPtr, v); IntList parentIdListPtr = netPtr.net_getParentIdListPtr(v); int numThreshold = 1 << parentIdListPtr.list_getSize(); - //int numThreshold = 1 << list_getSize(parentIdListPtr); int[] thresholds = new int[numThreshold]; - //int* thresholds = (int*)malloc(numThreshold * sizeof(int)); - //assert(thresholds); - //int t; for (int t = 0; t < numThreshold; t++) { int threshold = randomPtr.random_generate() % (DATA_PRECISION + 1); thresholds[t] = threshold; @@ -156,33 +140,21 @@ public class Data { */ int[] order = new int[numVar]; - //int* order = (int*)malloc(numVar * sizeof(int)); - //assert(order); int numOrder = 0; Queue workQueuePtr = Queue.queue_alloc(-1); - //queue_t* workQueuePtr = queue_alloc(-1); - //assert(workQueuePtr); IntVector dependencyVectorPtr = IntVector.vector_alloc(1); - //vector_t* dependencyVectorPtr = vector_alloc(1); - //assert(dependencyVectorPtr); BitMap orderedBitmapPtr = BitMap.bitmap_alloc(numVar); - //bitmap_t* orderedBitmapPtr = bitmap_alloc(numVar); - //assert(orderedBitmapPtr); orderedBitmapPtr.bitmap_clearAll(); BitMap doneBitmapPtr = BitMap.bitmap_alloc(numVar); - //bitmap_t* doneBitmapPtr = bitmap_alloc(numVar); - //assert(doneBitmapPtr); doneBitmapPtr.bitmap_clearAll(); - //bitmap_clearAle(doneBitmapPtr); + v = -1; - //while ((v = bitmap_findClear(doneBitmapPtr, (v + 1))) >= 0) while ((v = doneBitmapPtr.bitmap_findClear(v + 1)) >= 0) { IntList childIdListPtr = netPtr.net_getChildIdListPtr(v); - //list_t* childIdListPtr = net_getChildIdListPtr(netPtr, v); int numChild = childIdListPtr.list_getSize(); if (numChild == 0) { @@ -197,36 +169,30 @@ public class Data { System.out.println("status= "+ status + "should be true"); System.exit(0); } - //assert(status); + while (!(workQueuePtr.queue_isEmpty())) { int id = workQueuePtr.queue_pop(); if((status = doneBitmapPtr.bitmap_set(id)) != true) { System.out.println("status= "+ status + "should be true"); System.exit(0); } - //assert(status); - //CHECK THIS - if((status = dependencyVectorPtr.vector_pushBack(id)) != true) { + + if((status = dependencyVectorPtr.vector_pushBack(id)) == false) { System.out.println("status= "+ status + "should be true"); System.exit(0); } - //assert(status); - //list_t* parentIdListPtr = net_getParentIdListPtr(netPtr, id); - //list_iter_t it; - //list_iter_reset(&it, parentIdListPtr); + IntList parentIdListPtr = netPtr.net_getParentIdListPtr(id); IntListNode it = parentIdListPtr.head; parentIdListPtr.list_iter_reset(it); - //while (list_iter_hasNext(&it, parentIdListPtr)) + while (parentIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; - //int parentId = (int)list_iter_next(&it, parentIdListPtr); int parentId = parentIdListPtr.list_iter_next(it); - if((status = workQueuePtr.queue_push(parentId)) != true) { + if((status = workQueuePtr.queue_push(parentId)) == false) { System.out.println("status= "+ status + "should be true"); System.exit(0); } - //assert(status); } } @@ -234,7 +200,6 @@ public class Data { * Create ordering */ - //int i; int n = dependencyVectorPtr.vector_getSize(); for (int i = 0; i < n; i++) { int id = dependencyVectorPtr.vector_popBack(); @@ -250,31 +215,23 @@ public class Data { System.out.println("numVar should be equal to numOrder"); System.exit(0); } - //assert(numOrder == numVar); /* * Create records */ - char[] tmprecord = records; int startindex = 0; - //int r; - //int numRecord = dataPtr.numRecord; for (int r = 0; r < numRecord; r++) { - //int o; for (int o = 0; o < numOrder; o++) { v = order[o]; IntList parentIdListPtr = netPtr.net_getParentIdListPtr(v); - //list_t* parentIdListPtr = net_getParentIdListPtr(netPtr, v); int index = 0; - //list_iter_t it; - //list_iter_reset(&it, parentIdListPtr); IntListNode it = parentIdListPtr.head; parentIdListPtr.list_iter_reset(it); while (parentIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int parentId = parentIdListPtr.list_iter_next(it); - int value = tmprecord[parentId]; + int value = records[startindex + parentId]; if(value == DATA_INIT) { System.out.println("value should be != DATA_INIT"); System.exit(0); @@ -284,15 +241,13 @@ public class Data { } int rnd = randomPtr.random_generate() % DATA_PRECISION; int threshold = thresholdsTable[v][index]; - tmprecord[v] = (char) ((rnd < threshold) ? 1 : 0); + records[startindex + v] = (char) ((rnd < threshold) ? 1 : 0); } - //record += numVar; startindex += numVar; if(startindex > numRecord * numVar) { System.out.println("value should be != DATA_INIT in data_generate()"); System.exit(0); } - //assert(record <= (dataPtr.records + numRecord * numVar)); } /* @@ -304,40 +259,17 @@ public class Data { dependencyVectorPtr.vector_free(); workQueuePtr.queue_free(); order = null; - //bitmap_free(doneBitmapPtr); - //bitmap_free(orderedBitmapPtr); - //vector_free(dependencyVectorPtr); - //queue_free(workQueuePtr); - //free(order); + for (v = 0; v < numVar; v++) { thresholdsTable[v] = null; - //free(thresholdsTable[v]); } + thresholdsTable = null; - //free(thresholdsTable); return netPtr; } - /* ============================================================================= - * data_getRecord - * -- Returns null if invalid index - * ============================================================================= - */ - /* - char* - data_getRecord (data_t* dataPtr, int index) - { - if (index < 0 || index >= (dataPtr.numRecord)) { - return null; - } - - return &dataPtr.records[index * dataPtr.numVar]; - } - */ - - /* ============================================================================= * data_copy * -- Returns false on failure @@ -350,9 +282,7 @@ public class Data { int numSrcDatum = srcPtr.numVar * srcPtr.numRecord; if (numDstDatum != numSrcDatum) { dstPtr.records = null; - //free(dstPtr.records); dstPtr.records = new char[numSrcDatum]; - //dstPtr.records = (char*)calloc(numSrcDatum, sizeof(char)); if (dstPtr.records == null) { return false; } @@ -362,37 +292,10 @@ public class Data { dstPtr.numRecord = srcPtr.numRecord; for(int i=0; i 0) { - unsigned char u1 = (unsigned char)*s1++; - unsigned char u2 = (unsigned char)*s2++; - if (u1 != u2) { - return (u1 - u2); - } - } - - return 0; - } - */ - - /* ============================================================================= * data_sort * -- In place @@ -410,14 +313,7 @@ public class Data { if((start + num < 0) || (start + num > numRecord)) System.out.println("start + num: Assert failed in data_sort"); - //assert(start >= 0 && start <= dataPtr.numRecord); - //assert(num >= 0 && num <= dataPtr.numRecord); - //assert(start + num >= 0 && start + num <= dataPtr.numRecord); - - //int numVar = dataPtr.numVar; - //FIXME - //Sort.sort((dataPtr.records + (start * numVar)), Sort.sort(records, start * numVar, num, @@ -439,9 +335,6 @@ public class Data { int low = start; int high = start + num - 1; - //int numVar = dataPtr.numVar; - //char* records = dataPtr.records; - while (low <= high) { int mid = (low + high) / 2; if (records[numVar * mid + offset] == 0) { diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/FindBestTaskArg.java b/Robust/src/Benchmarks/SingleTM/Bayes/FindBestTaskArg.java index cbeb4059..0f3efb0c 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/FindBestTaskArg.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/FindBestTaskArg.java @@ -1,3 +1,11 @@ +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Helper class of Learner.java + **/ + public class FindBestTaskArg { int toId; Learner learnerPtr; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/IntList.java b/Robust/src/Benchmarks/SingleTM/Bayes/IntList.java index a41d6d78..55b54114 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/IntList.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/IntList.java @@ -9,7 +9,7 @@ * Copyright (C) Stanford University, 2006. All Rights Reserved. * Author: Chi Cao Minh * - * Ported to Java June 2006, Alokika Dash + * Ported to Java June 2009, Alokika Dash * adash@uci.edu * University of California, Irvine * @@ -90,7 +90,6 @@ public class IntList { public int list_iter_next (IntListNode itPtr) { - //itPtr = itPtr.nextPtr; return itPtr.dataPtr; } @@ -144,7 +143,6 @@ public class IntList { freeNode (IntListNode nodePtr) { nodePtr = null; - //free(nodePtr); } diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/IntListNode.java b/Robust/src/Benchmarks/SingleTM/Bayes/IntListNode.java index bb66db9a..ee3b2e73 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/IntListNode.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/IntListNode.java @@ -1,3 +1,11 @@ +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Helper class for IntList.java + **/ + public class IntListNode { public int dataPtr; public IntListNode nextPtr; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/IntVector.java b/Robust/src/Benchmarks/SingleTM/Bayes/IntVector.java index b07a76c8..239dd06b 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/IntVector.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/IntVector.java @@ -1,3 +1,11 @@ +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Vector class for "ints" elements + **/ + public class IntVector { int size; int capacity; @@ -60,7 +68,6 @@ public class IntVector { int newCapacity = capacity * 2; int[] newElements = new int[newCapacity]; - //void** newElements = (void**)malloc(newCapacity * sizeof(void*)); if (newElements == null) { return false; } @@ -119,8 +126,7 @@ public class IntVector { public void vector_sort () { - //qsort.sort(elements, 0, (elements.length - 1)); - //qsort(elements, size, 4, compare); + qsort.sort(elements, 0, (elements.length - 1)); } /* ============================================================================= diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java b/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java index 0ae389fc..a7104b83 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java @@ -7,6 +7,9 @@ * * Copyright (C) Stanford University, 2006. All Rights Reserved. * Author: Chi Cao Minh + * Ported to Java June 2009 Alokika Dash + * University of California, Irvine + * * * ============================================================================= * @@ -194,18 +197,12 @@ public class Learner { * ============================================================================= */ public void - //learner_free (learner_t* learnerPtr) learner_free () { taskListPtr.list_free(); tasks = null; localBaseLogLikelihoods = null; netPtr.net_free(); - //free(learnerPtr.tasks); - //free(learnerPtr.localBaseLogLikelihoods); - //net_free(learnerPtr.netPtr); - this = null; - //free(learnerPtr); } @@ -232,9 +229,6 @@ public class Learner { System.exit(0); } - //assert(parentCount >= count); - //assert(parentCount > 0); - float fval = (float)(probability * (Math.log((double)count/ (double)parentCount))); return fval; } @@ -553,11 +547,17 @@ public class Learner { boolean status; status = Vector_t.vector_copy(queryVectorPtr, parentQueryVectorPtr); - //TODO CHECK ASSERT - //assert(status); + if(status == false ) { + System.out.println("Assert failed: whille vector copy in populateQueryVectors()"); + System.exit(0); + } + status = queryVectorPtr.vector_pushBack(queries[id]); - //TODO CHECK ASSERT - //assert(status); + if(status == false ) { + System.out.println("Assert failed: whille vector pushBack in populateQueryVectors()"); + System.exit(0); + } + queryVectorPtr.vector_sort(); } @@ -608,7 +608,6 @@ public class Learner { float localLogLikelihood = 0.0f; - //query_t* parentQueryPtr = vector_at(parentQueryVectorPtr, i); Query parentQueryPtr = (Query) (parentQueryVectorPtr.vector_at(i)); int parentIndex = parentQueryPtr.index; @@ -1519,20 +1518,13 @@ public class Learner { public float learner_score () { - //adtree_t* adtreePtr = learnerPtr.adtreePtr; - //net_t* netPtr = learnerPtr.netPtr; Vector_t queryVectorPtr = Vector_t.vector_alloc(1); - //assert(queryVectorPtr); Vector_t parentQueryVectorPtr = Vector_t.vector_alloc(1); - //vector_t* parentQueryVectorPtr = vector_alloc(1); - //assert(parentQueryVectorPtr); int numVar = adtreePtr.numVar; Query[] queries = new Query[numVar]; - //query_t* queries = (query_t*)malloc(numVar * sizeof(query_t)); - //assert(queries); - //int v; + for (int v = 0; v < numVar; v++) { queries[v] = new Query(); queries[v].index = v; @@ -1545,7 +1537,6 @@ public class Learner { for (int v = 0; v < numVar; v++) { IntList parentIdListPtr = netPtr.net_getParentIdListPtr(v); - //list_t* parentIdListPtr = net_getParentIdListPtr(netPtr, v); numTotalParent += parentIdListPtr.list_getSize(); @@ -1566,9 +1557,7 @@ public class Learner { queryVectorPtr.vector_free(); parentQueryVectorPtr.vector_free(); queries = null; - //vector_free(queryVectorPtr); - //vector_free(parentQueryVectorPtr); - //free(queries); + int numRecord = adtreePtr.numRecord; float penalty = (float)(-0.5f * (double)numTotalParent * Math.log((double)numRecord)); @@ -1576,86 +1565,6 @@ public class Learner { return score; } - - - /* ############################################################################# - * TEST_LEARNER - * ############################################################################# - */ - /* -#ifdef TEST_LEARNER - -#include - - -static void -testPartition (int min, int max, int n) -{ -int start; -int stop; - -printf("min=%li max=%li, n=%li\n", min, max, n); - -int i; -for (i = 0; i < n; i++) { -createPartition(min, max, i, n, &start, &stop); -printf("%li: %li . %li\n", i, start, stop); -} -puts(""); -} - - -int -main (int argc, char* argv[]) -{ -thread_startup(1); - -puts("Starting..."); - -testPartition(0, 4, 8); -testPartition(0, 15, 8); -testPartition(3, 103, 7); - -int numVar = 56; -int numRecord = 256; - -random_t* randomPtr = random_alloc(); -data_t* dataPtr = data_alloc(numVar, numRecord, randomPtr); -assert(dataPtr); -data_generate(dataPtr, 0, 10, 10); - -adtree_t* adtreePtr = adtree_alloc(); -assert(adtreePtr); -adtree_make(adtreePtr, dataPtr); - - -learner_t* learnerPtr = learner_alloc(dataPtr, adtreePtr, 1); -assert(learnerPtr); - -data_free(dataPtr); - -learner_run(learnerPtr); - -assert(!net_isCycle(learnerPtr.netPtr)); - -float score = learner_score(learnerPtr); -printf("score = %lf\n", score); - -learner_free(learnerPtr); - -puts("Done."); - -adtree_free(adtreePtr); -random_free(randomPtr); - -thread_shutdown(); - -return 0; -} - -#endif // TEST_LEARNER -*/ - } /* ============================================================================= diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/LearnerTask.java b/Robust/src/Benchmarks/SingleTM/Bayes/LearnerTask.java index 9f01d6eb..a611e09f 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/LearnerTask.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/LearnerTask.java @@ -1,3 +1,11 @@ + +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Helper class for Learner.java + **/ public class LearnerTask { Operation op; int fromId; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Net.java b/Robust/src/Benchmarks/SingleTM/Bayes/Net.java index 872436a4..c6bdb411 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Net.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Net.java @@ -56,20 +56,6 @@ * ============================================================================ */ - -/* -#include -#include -#include "bitmap.h" -#include "learner.h" -#include "list.h" -#include "net.h" -#include "operation.h" -#include "queue.h" -#include "tm.h" -#include "vector.h" -*/ - #define NET_NODE_MARK_INIT 0 #define NET_NODE_MARK_DONE 1 #define NET_NODE_MARK_TEST 2 @@ -84,42 +70,6 @@ public class Net { public Net() { } - /* - typedef enum net_node_mark { - NET_NODE_MARK_INIT = 0, - NET_NODE_MARK_DONE = 1, - NET_NODE_MARK_TEST = 2, - } net_node_mark_t; - - typedef struct net_node { - int id; - list_t* parentIdListPtr; - list_t* childIdListPtr; - net_node_mark_t mark; - } net_node_t; - - struct net { - vector_t* nodeVectorPtr; - }; - */ - - - /* ============================================================================= - * compareId - * ============================================================================= - */ - /* - public static int - compareId (const void* aPtr, const void* bPtr) - { - int a = (int)aPtr; - int b = (int)bPtr; - - return (a - b); - } - */ - - /* ============================================================================= * allocNode * ============================================================================= @@ -128,21 +78,20 @@ public class Net { { NetNode nodePtr = new NetNode(); - //nodePtr = (net_node_t*)malloc(sizeof(net_node_t)); - //if (nodePtr) { - nodePtr.parentIdListPtr = IntList.list_alloc(); - if (nodePtr.parentIdListPtr == null) { - nodePtr = null; - return null; - } - nodePtr.childIdListPtr = IntList.list_alloc(); - if (nodePtr.childIdListPtr == null) { - nodePtr.parentIdListPtr.list_free(); - nodePtr = null; - return null; + if (nodePtr != null) { + nodePtr.parentIdListPtr = IntList.list_alloc(); + if (nodePtr.parentIdListPtr == null) { + nodePtr = null; + return null; + } + nodePtr.childIdListPtr = IntList.list_alloc(); + if (nodePtr.childIdListPtr == null) { + nodePtr.parentIdListPtr.list_free(); + nodePtr = null; + return null; + } + nodePtr.id = id; } - nodePtr.id = id; - //} return nodePtr; } @@ -155,40 +104,29 @@ public class Net { public static Net net_alloc (int numNode) { Net netPtr = new Net(); - Vector_t nodeVectorPtr = Vector_t.vector_alloc(numNode); - if (nodeVectorPtr == null) { - netPtr = null; - return null; - } - //netPtr = (net_t*)malloc(sizeof(net_t)); - //if (netPtr) { - // vector_t* nodeVectorPtr = vector_alloc(numNode); - // if (nodeVectorPtr == null) { - // free(netPtr); - // return null; - // } - // int i; - for (int i = 0; i < numNode; i++) { - NetNode nodePtr = allocNode(i); - //net_node_t* nodePtr = allocNode(i); - if (nodePtr == null) { - for (int j = 0; j < i; j++) { - //nodePtr = (net_node_t*)vector_at(nodeVectorPtr, j); - nodePtr = (NetNode)(nodeVectorPtr.vector_at(j)); - nodePtr.freeNode(); - } - nodeVectorPtr.vector_free(); + if (netPtr != null) { + Vector_t nodeVectorPtr = Vector_t.vector_alloc(numNode); + if (nodeVectorPtr == null) { netPtr = null; - //free(netPtr); return null; } - boolean status = nodeVectorPtr.vector_pushBack(nodePtr); - //boolean status = vector_pushBack(nodeVectorPtr, (void*)nodePtr); - //assert(status); + for (int i = 0; i < numNode; i++) { + NetNode nodePtr = allocNode(i); + if (nodePtr == null) { + for (int j = 0; j < i; j++) { + nodePtr = (NetNode)(nodeVectorPtr.vector_at(j)); + nodePtr.freeNode(); + } + nodeVectorPtr.vector_free(); + netPtr = null; + return null; + } + + boolean status = nodeVectorPtr.vector_pushBack(nodePtr); + } + netPtr.nodeVectorPtr = nodeVectorPtr; } - netPtr.nodeVectorPtr = nodeVectorPtr; - //} return netPtr; } @@ -201,16 +139,12 @@ public class Net { public void net_free () { - //int i; - //vector_t* nodeVectorPtr = netPtr.nodeVectorPtr; int numNode = nodeVectorPtr.vector_getSize(); for (int i = 0; i < numNode; i++) { NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(i)); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, i); nodePtr.freeNode(); } nodeVectorPtr.vector_free(); - //free(netPtr); } @@ -221,30 +155,23 @@ public class Net { public void insertEdge (int fromId, int toId) { - //vector_t* nodeVectorPtr = netPtr.nodeVectorPtr; boolean status; NetNode childNodePtr = (NetNode)(nodeVectorPtr.vector_at(toId)); IntList parentIdListPtr = childNodePtr.parentIdListPtr; - //net_node_t* childNodePtr = (net_node_t*)vector_at(nodeVectorPtr, toId); - //list_t* parentIdListPtr = childNodePtr.parentIdListPtr; + if((status = parentIdListPtr.list_insert(fromId)) != true) { System.out.println("Assert failed for parentIdListPtr.list_insert in insertEdge()"); System.exit(0); } - //status = list_insert(parentIdListPtr, (void*)fromId); - //assert(status); NetNode parentNodePtr = (NetNode)(nodeVectorPtr.vector_at(fromId)); IntList childIdListPtr = parentNodePtr.childIdListPtr; - //net_node_t* parentNodePtr = (net_node_t*)vector_at(nodeVectorPtr, fromId); - //list_t* childIdListPtr = parentNodePtr.childIdListPtr; + if((status = childIdListPtr.list_insert(toId)) != true) { System.out.println("Assert failed for childIdListPtr.list_insert in insertEdge()"); System.exit(0); } - //status = list_insert(childIdListPtr, (void*)toId); - //assert(status); } @@ -282,20 +209,15 @@ public class Net { boolean status; NetNode childNodePtr = (NetNode)(nodeVectorPtr.vector_at(toId)); - //net_node_t* childNodePtr = (net_node_t*)vector_at(nodeVectorPtr, toId); IntList parentIdListPtr = childNodePtr.parentIdListPtr; - //list_t* parentIdListPtr = childNodePtr.parentIdListPtr; status = parentIdListPtr.list_remove(fromId); if(status == false) { System.out.println("Assert failed: when removing from list"); System.exit(0); } - //assert(status); NetNode parentNodePtr = (NetNode)(nodeVectorPtr.vector_at(fromId)); - //net_node_t* parentNodePtr = (net_node_t*)vector_at(nodeVectorPtr, fromId); IntList childIdListPtr = parentNodePtr.childIdListPtr; - //list_t* childIdListPtr = parentNodePtr.childIdListPtr; status = childIdListPtr.list_remove(toId); if(status == false) { System.out.println("Assert failed: when removing from list"); @@ -331,7 +253,6 @@ public class Net { * ============================================================================= */ public void - //reverseEdge (net_t* netPtr, int fromId, int toId) reverseEdge (int fromId, int toId) { removeEdge(fromId, toId); @@ -401,16 +322,11 @@ public class Net { public boolean net_hasEdge (int fromId, int toId) { - //vector_t* nodeVectorPtr = netPtr.nodeVectorPtr; NetNode childNodePtr = (NetNode)(nodeVectorPtr.vector_at(toId)); - //net_node_t* childNodePtr = (net_node_t*)vector_at(nodeVectorPtr, toId); IntList parentIdListPtr = childNodePtr.parentIdListPtr; IntListNode it = parentIdListPtr.head; //intialize iterator parentIdListPtr.list_iter_reset(it); - //list_iter_t it; - //list_iter_reset(&it, parentIdListPtr); - //while (list_iter_hasNext(&it, parentIdListPtr)) { while (parentIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; @@ -462,25 +378,18 @@ public class Net { { boolean status; - //Vector_t nodeVectorPtr = netPtr.nodeVectorPtr; if(visitedBitmapPtr.numBit != nodeVectorPtr.vector_getSize()) { System.out.println("Assert failed for numbit == vector size in net_isPath()"); System.exit(0); } - //vector_t* nodeVectorPtr = netPtr.nodeVectorPtr; - //assert(visitedBitmapPtr.numBit == vector_getSize(nodeVectorPtr)); visitedBitmapPtr.bitmap_clearAll(); workQueuePtr.queue_clear(); - //bitmap_clearAll(visitedBitmapPtr); - //queue_clear(workQueuePtr); if((status = workQueuePtr.queue_push(fromId)) != true) { System.out.println("Assert failed while inserting into Queue in net_isPath()"); System.exit(0); } - //status = queue_push(workQueuePtr, (void*)fromId); - //assert(status); while (!workQueuePtr.queue_isEmpty()) { int id = workQueuePtr.queue_pop(); @@ -488,21 +397,17 @@ public class Net { workQueuePtr.queue_clear(); return true; } + if((status = visitedBitmapPtr.bitmap_set(id)) != true) { System.out.println("Assert failed while checking bitmap_set in net_isPath()"); System.exit(0); } - //status = bitmap_set(visitedBitmapPtr, id); - //assert(status); + NetNode nodePtr = (NetNode) (nodeVectorPtr.vector_at(id)); IntList childIdListPtr = nodePtr.childIdListPtr; IntListNode it = childIdListPtr.head; childIdListPtr.list_iter_reset(it); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id); - //list_t* childIdListPtr = nodePtr.childIdListPtr; - //list_iter_t it; - //list_iter_reset(&it, childIdListPtr); - //while (list_iter_hasNext(&it, childIdListPtr)) + while (childIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int childId = childIdListPtr.list_iter_next(it); @@ -512,7 +417,6 @@ public class Net { System.out.println("Assert failed: queue_push failed in net_isPath()"); System.exit(0); } - //assert(status); } } } @@ -583,19 +487,16 @@ public class Net { IntList childIdListPtr = nodePtr.childIdListPtr; IntListNode it = childIdListPtr.head; childIdListPtr.list_iter_reset(it); - //list_iter_t it; - //list_iter_reset(&it, childIdListPtr); - //while (list_iter_hasNext(&it, childIdListPtr)) + while (childIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int childId = childIdListPtr.list_iter_next(it); NetNode childNodePtr = (NetNode)(nodeVectorPtr.vector_at(childId)); - //net_node_t* childNodePtr = - // (net_node_t*)vector_at(nodeVectorPtr, childId); if (isCycle(nodeVectorPtr, childNodePtr)) { return true; } } + } else if(nodePtr.mark == NET_NODE_MARK_TEST) { return true; } else if(nodePtr.mark == NET_NODE_MARK_DONE) { @@ -615,21 +516,16 @@ public class Net { * ============================================================================= */ public boolean - //net_isCycle (net_t* netPtr) net_isCycle () { - //vector_t* nodeVectorPtr = netPtr.nodeVectorPtr; int numNode = nodeVectorPtr.vector_getSize(); - //int n; for (int n = 0; n < numNode; n++) { NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(n)); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, n); nodePtr.mark = NET_NODE_MARK_INIT; } for (int n = 0; n < numNode; n++) { NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(n)); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, n); if(nodePtr.mark == NET_NODE_MARK_INIT) { if(isCycle(nodeVectorPtr, nodePtr)) return true; @@ -637,12 +533,12 @@ public class Net { /* do nothing */ ; } else if(nodePtr.mark == NET_NODE_MARK_TEST) { - /* Assert 0 */ + /* Assert 0 */ System.out.println("We should have never come here in net_isCycle()"); System.exit(0); break; } else { - /* Assert 0 */ + /* Assert 0 */ System.out.println("We should have never come here in net_isCycle()"); System.exit(0); break; @@ -700,27 +596,20 @@ public class Net { { boolean status; - //vector_t* nodeVectorPtr = netPtr.nodeVectorPtr; - if(ancestorBitmapPtr.numBit != nodeVectorPtr.vector_getSize()) { System.out.println("Assert failed for numbit == vector size in net_findAncestors()"); System.exit(0); } - //assert(ancestorBitmapPtr.numBit == vector_getSize(nodeVectorPtr)); ancestorBitmapPtr.bitmap_clearAll(); workQueuePtr.queue_clear(); { NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(id)); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id); IntList parentIdListPtr = nodePtr.parentIdListPtr; IntListNode it = parentIdListPtr.head; parentIdListPtr.list_iter_reset(it); - //list_t* parentIdListPtr = nodePtr.parentIdListPtr; - //list_iter_t it; - //list_iter_reset(&it, parentIdListPtr); - //while (list_iter_hasNext(&it, parentIdListPtr)) + while (parentIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int parentId = parentIdListPtr.list_iter_next(it); @@ -729,13 +618,12 @@ public class Net { System.out.println("Assert failed: for bitmap_set in net_findAncestors()"); System.exit(0); } - //assert(status); if((status = workQueuePtr.queue_push(parentId)) == false) { System.out.println("Assert failed: for workQueuePtr.queue_push in net_findAncestors()"); System.exit(0); } - //assert(status); } + } while (!workQueuePtr.queue_isEmpty()) { @@ -745,13 +633,10 @@ public class Net { return false; } NetNode nodePtr = (NetNode)(nodeVectorPtr.vector_at(parentId)); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, parentId); IntList grandParentIdListPtr = nodePtr.parentIdListPtr; IntListNode it = grandParentIdListPtr.head; grandParentIdListPtr.list_iter_reset(it); - //list_t* grandParentIdListPtr = nodePtr.parentIdListPtr; - //list_iter_t it; - //list_iter_reset(&it, grandParentIdListPtr); + while (grandParentIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int grandParentId = grandParentIdListPtr.list_iter_next(it); @@ -760,12 +645,11 @@ public class Net { System.out.println("Assert failed: for ancestorBitmapPtr bitmap_set in net_findAncestors()"); System.exit(0); } - //assert(status); + if((status = workQueuePtr.queue_push(grandParentId)) == false) { System.out.println("Assert failed: for workQueuePtr.queue_push in net_findAncestors()"); System.exit(0); } - //assert(status); } } } @@ -865,10 +749,6 @@ public class Net { IntListNode it = childIdListPtr.head; childIdListPtr.list_iter_reset(it); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id); - //list_t* childIdListPtr = nodePtr.childIdListPtr; - //list_iter_t it; - //list_iter_reset(&it, childIdListPtr); while (childIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int childId = childIdListPtr.list_iter_next(it); @@ -876,12 +756,12 @@ public class Net { System.out.println("Assert failed: for descendantBitmapPtr.bitmap_set in net_findDescendants()"); System.exit(0); } - //assert(status); + if((status = workQueuePtr.queue_push(childId)) == false) { System.out.println("Assert failed: for workQueuePtr.queue_push in net_findDescendants()"); System.exit(0); } - //assert(status); + } } @@ -896,11 +776,7 @@ public class Net { IntList grandChildIdListPtr = nodePtr.childIdListPtr; IntListNode it = grandChildIdListPtr.head; grandChildIdListPtr.list_iter_reset(it); - //net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, childId); - //list_t* grandChildIdListPtr = nodePtr.childIdListPtr; - //list_iter_t it; - //list_iter_reset(&it, grandChildIdListPtr); - //while (list_iter_hasNext(&it, grandChildIdListPtr)) + while (grandChildIdListPtr.list_iter_hasNext(it)) { it = it.nextPtr; int grandChildId = grandChildIdListPtr.list_iter_next(it); @@ -909,12 +785,11 @@ public class Net { System.out.println("Assert failed: for descendantBitmapPtr.bitmap_set in net_findDescendants()"); System.exit(0); } - //assert(status); + if((status = workQueuePtr.queue_push(grandChildId)) == false) { System.out.println("Assert failed: for workQueuePtr.queue_push in net_findDescendants()"); System.exit(0); } - //assert(status); } } } @@ -995,22 +870,16 @@ public class Net { int percentParent, Random randomPtr) { - //Vector_t nodeVectorPtr = netPtr.nodeVectorPtr; - int numNode = nodeVectorPtr.vector_getSize(); BitMap visitedBitmapPtr = BitMap.bitmap_alloc(numNode); if(visitedBitmapPtr == null) { System.out.println("Assert failed: during bitmap_alloc in net_generateRandomEdges()"); System.exit(0); } - //assert(visitedBitmapPtr); - Queue workQueuePtr = Queue.queue_alloc(-1); - //Queue* workQueuePtr = queue_alloc(-1); - //int n; + Queue workQueuePtr = Queue.queue_alloc(-1); for (int n = 0; n < numNode; n++) { - //int p; for (int p = 0; p < maxNumParent; p++) { int value = randomPtr.random_generate() % 100; if (value < percentParent) { @@ -1019,9 +888,6 @@ public class Net { !net_hasEdge(parent, n) && !net_isPath(n, parent, visitedBitmapPtr, workQueuePtr)) { -#ifdef TEST_NET - System.out.println("node=" + n + " parent= " + parent); -#endif insertEdge(parent, n); } } @@ -1032,109 +898,12 @@ public class Net { System.out.println("Assert failed: Cycle detected in net_generateRandomEdges()"); System.exit(0); } - //assert(!net_isCycle(netPtr)); visitedBitmapPtr.bitmap_free(); workQueuePtr.queue_free(); } - - - /* ############################################################################# - * TEST_NET - * ############################################################################# - */ - /* -#ifdef TEST_NET - -#include - - -int -main () -{ -int numNode = 100; - -puts("Starting tests..."); - -boolean status; - -net_t* netPtr = net_alloc(numNode); -assert(netPtr); -Bitmap* visitedBitmapPtr = bitmap_alloc(numNode); -assert(visitedBitmapPtr); -Queue* workQueuePtr = queue_alloc(-1); -assert(workQueuePtr); - -assert(!net_isCycle(netPtr)); - -int aId = 31; -int bId = 14; -int cId = 5; -int dId = 92; - -net_applyOperation(netPtr, OPERATION_INSERT, aId, bId); -assert(net_isPath(netPtr, aId, bId, visitedBitmapPtr, workQueuePtr)); -assert(!net_isPath(netPtr, bId, aId, visitedBitmapPtr, workQueuePtr)); -assert(!net_isPath(netPtr, aId, cId, visitedBitmapPtr, workQueuePtr)); -assert(!net_isPath(netPtr, aId, dId, visitedBitmapPtr, workQueuePtr)); -assert(!net_isCycle(netPtr)); - -net_applyOperation(netPtr, OPERATION_INSERT, bId, cId); -net_applyOperation(netPtr, OPERATION_INSERT, aId, cId); -net_applyOperation(netPtr, OPERATION_INSERT, dId, aId); -assert(!net_isCycle(netPtr)); -net_applyOperation(netPtr, OPERATION_INSERT, cId, dId); -assert(net_isCycle(netPtr)); -net_applyOperation(netPtr, OPERATION_REVERSE, cId, dId); -assert(!net_isCycle(netPtr)); -net_applyOperation(netPtr, OPERATION_REVERSE, dId, cId); -assert(net_isCycle(netPtr)); -assert(net_isPath(netPtr, aId, dId, visitedBitmapPtr, workQueuePtr)); -net_applyOperation(netPtr, OPERATION_REMOVE, cId, dId); -assert(!net_isPath(netPtr, aId, dId, visitedBitmapPtr, workQueuePtr)); - -Bitmap* ancestorBitmapPtr = bitmap_alloc(numNode); -assert(ancestorBitmapPtr); -status = net_findAncestors(netPtr, cId, ancestorBitmapPtr, workQueuePtr); -assert(status); -assert(bitmap_isSet(ancestorBitmapPtr, aId)); -assert(bitmap_isSet(ancestorBitmapPtr, bId)); -assert(bitmap_isSet(ancestorBitmapPtr, dId)); -assert(bitmap_getNumSet(ancestorBitmapPtr) == 3); - -Bitmap* descendantBitmapPtr = bitmap_alloc(numNode); -assert(descendantBitmapPtr); -status = net_findDescendants(netPtr, aId, descendantBitmapPtr, workQueuePtr); -assert(status); -assert(bitmap_isSet(descendantBitmapPtr, bId)); -assert(bitmap_isSet(descendantBitmapPtr, cId)); -assert(bitmap_getNumSet(descendantBitmapPtr) == 2); - -bitmap_free(visitedBitmapPtr); -queue_free(workQueuePtr); -bitmap_free(ancestorBitmapPtr); -bitmap_free(descendantBitmapPtr); - net_free(netPtr); - - random_t* randomPtr = random_alloc(); - assert(randomPtr); - netPtr = net_alloc(numNode); - assert(netPtr); - net_generateRandomEdges(netPtr, 10, 10, randomPtr); - net_free(netPtr); - - puts("All tests passed."); - - return 0; } - -#endif // TEST_NET -*/ - -} - - /* ============================================================================= * * End of net.java diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/NetNode.java b/Robust/src/Benchmarks/SingleTM/Bayes/NetNode.java index 50a81da6..a76d6baa 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/NetNode.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/NetNode.java @@ -1,3 +1,11 @@ +/** + * Author: Alokika Dash + * University of California, Irvine + * adash@uci.edu + * + * - Helper class for Net.java + **/ + public class NetNode { int id; int mark; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java b/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java index 30272640..6cc0dd77 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java @@ -45,24 +45,6 @@ * * ------------------------------------------------------------------------ * - * For the license of kmeans, please see kmeans/LICENSE.kmeans - * - * ------------------------------------------------------------------------ - * - * For the license of ssca2, please see ssca2/COPYRIGHT - * - * ------------------------------------------------------------------------ - * - * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the - * header of the files. - * - * ------------------------------------------------------------------------ - * - * For the license of lib/rbtree.h and lib/rbtree.c, please see - * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree - * - * ------------------------------------------------------------------------ - * * Unless otherwise noted, the following license applies to STAMP files: * * Copyright (c) 2007, Stanford University @@ -99,8 +81,6 @@ * ============================================================================= */ -//#include "sort.h" - #define CUTOFF 8 public class Sort { @@ -167,23 +147,41 @@ public class Sort { return; } + /** + * Pointers that keep track of + * where to start looking in + * the base array + **/ + char[] lostk= new char[30]; + char[] histk= new char[30]; + + int stkptr = 0; + int lo = start; int hi = start + (width * (num - 1)); + int size = 0; + + /** + * debug + **/ //System.out.println("start= " + start + " base.length= " + base.length + " hi= " + hi); - recurse(base, lo, hi, width, n, offset); + recurse(base, lo, hi, width, n, offset, lostk, histk, stkptr, size); } - public void recurse(char[] base, int lo, int hi, int width, int n, int offset) + public void recurse(char[] base, + int lo, + int hi, + int width, + int n, + int offset, + char[] lostk, + char[] histk, + int stkptr, + int size) { - char[] lostk= new char[30]; - char[] histk= new char[30]; - - int stkptr = 0; - int size; - //recurse: size = (hi - lo) / width + 1; @@ -224,7 +222,7 @@ public class Sort { if (loguy < hi) { lo = loguy; - recurse(base, lo, hi, width, n, offset); + recurse(base, lo, hi, width, n, offset, lostk, histk, stkptr, size); } } else { if (loguy < hi) { @@ -234,7 +232,7 @@ public class Sort { } if (lo + width < higuy) { hi = higuy - width; - recurse(base, lo, hi, width, n, offset); + recurse(base, lo, hi, width, n, offset, lostk, histk, stkptr, size); } } } @@ -243,7 +241,7 @@ public class Sort { if (stkptr >= 0) { base[lo] = lostk[stkptr]; base[hi] = histk[stkptr]; - recurse(base, lo, hi, width, n, offset); + recurse(base, lo, hi, width, n, offset, lostk, histk, stkptr, size); } } @@ -258,22 +256,18 @@ public class Sort { int s1 = p1 + offset; int s2 = p2 + offset; - //const char* s1 = (const char*)p1 + offset; - //const char* s2 = (const char*)p2 + offset; - while (i-- > 0) { char u1 = base[s1]; char u2 = base[s2]; - //unsigned char u1 = (unsigned char)*s1++; - //unsigned char u2 = (unsigned char)*s2++; if (u1 != u2) { - return (u1 - u2); //CAN YOU DO THIS + return (u1 - u2); //TODO check this in java } } return 0; } } + /* ============================================================================= * * End of sort.java diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/makefile b/Robust/src/Benchmarks/SingleTM/Bayes/makefile index 52305979..739fcb32 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/makefile +++ b/Robust/src/Benchmarks/SingleTM/Bayes/makefile @@ -21,7 +21,8 @@ SRC=tmp${MAINCLASS}.java \ ../common/ListNode.java \ ../common/List.java \ ../common/QuickSort.java \ - IntVector.java + IntVector.java \ + ../../../ClassLibrary/JavaSTM/Barrier.java FLAGS=-mainclass ${MAINCLASS} -thread -nooptimize -debug