id
int32
0
12.9k
code
sequencelengths
2
264k
9,100
[ "<s>", "package", "com", ".", "smartgrid", ".", "app", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "com", ".", "smartgrid", ".", "app", ".", "Aggregator", ";", "import", "com", ".", "smartgrid", ".", "messenger", ".", "Message", ";", "import", "com", ".", "smartgrid", ".", "messenger", ".", "Messenger", ";", "import", "com", ".", "smartgrid", ".", "messenger", ".", "MessengerBasic", ";", "import", "com", ".", "smartgrid", ".", "policies", ".", "AggregatorPolicy", ";", "import", "com", ".", "smartgrid", ".", "policies", ".", "HouseholdPolicy", ";", "public", "class", "Simulator", "{", "private", "Long", "tick", "=", "0L", ";", "private", "Long", "iterations", ";", "private", "Long", "startTime", ";", "private", "Long", "currentTime", ";", "private", "Messenger", "<", "Household", ">", "messenger", ";", "private", "Integer", "granularity", ";", "private", "AggregatorPolicy", "aggregatorPolicy", ";", "private", "Aggregator", "aggregator", ";", "private", "Logger", "logger", ";", "public", "Simulator", "(", "HashMap", "<", "Integer", ",", "Household", ">", "households", ",", "Long", "iterations", ",", "Integer", "granularity", ",", "AggregatorPolicy", "aggregatorPolicy", ",", "Logger", "logger", ")", "{", "this", ".", "iterations", "=", "iterations", ";", "this", ".", "granularity", "=", "granularity", ";", "this", ".", "aggregatorPolicy", "=", "aggregatorPolicy", ";", "messenger", "=", "new", "MessengerBasic", "<", "Household", ">", "(", "households", ")", ";", "aggregator", "=", "new", "Aggregator", "(", "messenger", ",", "logger", ")", ";", "aggregator", ".", "setElectricitySupply", "(", "aggregatorPolicy", ".", "getSupply", "(", ")", ")", ";", "aggregator", ".", "setElectricityPrice", "(", "aggregatorPolicy", ".", "getPrice", "(", ")", ")", ";", "this", ".", "logger", "=", "logger", ";", "}", "private", "void", "tick", "(", "Date", "date", ")", "{", "messenger", ".", "<", "Void", ",", "Date", ">", "messageMany", "(", "messenger", ".", "memberIds", "(", ")", ",", "new", "Message", "<", "Date", ">", "(", "\"tick\"", ",", "date", ")", ")", ";", "aggregator", ".", "updateApplianceMap", "(", ")", ";", "Double", "overallDemand", "=", "aggregator", ".", "updateHouseholdDemands", "(", "date", ")", ";", "logger", ".", "logAggregator", "(", "date", ",", "aggregator", ".", "getElectricitySupply", "(", ")", ",", "overallDemand", ",", "aggregator", ".", "getElectricityPrice", "(", ")", ")", ";", "aggregatorPolicy", ".", "tick", "(", "date", ",", "aggregator", ")", ";", "}", "public", "void", "run", "(", ")", "{", "currentTime", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "while", "(", "tick", "<=", "iterations", ")", "{", "tick", "++", ";", "currentTime", "+=", "1000L", "*", "granularity", ";", "tick", "(", "new", "Date", "(", "currentTime", ")", ")", ";", "}", "}", "}", "</s>" ]
9,101
[ "<s>", "package", "com", ".", "smartgrid", ".", "app", ";", "import", "com", ".", "smartgrid", ".", "policies", ".", "Appliance", ";", "import", "com", ".", "smartgrid", ".", "policies", ".", "HouseholdPolicy", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "List", ";", "public", "class", "Household", "{", "private", "Integer", "householdId", ";", "private", "HouseholdPolicy", "policy", ";", "public", "Household", "(", "Integer", "householdId", ",", "HouseholdPolicy", "policy", ")", "{", "this", ".", "householdId", "=", "householdId", ";", "this", ".", "policy", "=", "policy", ";", "}", "private", "void", "logMessage", "(", "String", "msg", ")", "{", "System", ".", "out", ".", "printf", "(", "\"\"", ",", "policy", ".", "getClass", "(", ")", ".", "toString", "(", ")", ",", "householdId", ",", "msg", ")", ";", "}", "public", "void", "tick", "(", "Date", "date", ")", "{", "logMessage", "(", "\"tick\"", ")", ";", "policy", ".", "tick", "(", "date", ")", ";", "}", "public", "Integer", "getHouseholdId", "(", ")", "{", "return", "householdId", ";", "}", "public", "HouseholdPolicy", "getPolicy", "(", ")", "{", "return", "policy", ";", "}", "public", "Double", "getElectricityDemand", "(", ")", "{", "Double", "demand", "=", "policy", ".", "getElectricityDemand", "(", ")", ";", "logMessage", "(", "String", ".", "format", "(", "\"demand", "%f\"", ",", "demand", ")", ")", ";", "return", "demand", ";", "}", "public", "List", "<", "Appliance", ">", "getAppliances", "(", ")", "{", "return", "policy", ".", "getAppliances", "(", ")", ";", "}", "public", "Integer", "turnOffAppliance", "(", "Appliance", "appliance", ")", "{", "logMessage", "(", "\"\"", ")", ";", "return", "policy", ".", "turnOffAppliance", "(", "appliance", ")", ";", "}", "public", "void", "notifyPrice", "(", "Double", "newPrice", ")", "{", "logMessage", "(", "String", ".", "format", "(", "\"new", "price", "%f\"", ",", "newPrice", ")", ")", ";", "policy", ".", "notifyPrice", "(", "newPrice", ")", ";", "}", "public", "CustomMessage", "handleMessage", "(", "CustomMessage", "in", ")", "throws", "Exception", "{", "return", "policy", ".", "handleMessage", "(", "in", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"\"", "+", "householdId", "+", "\"\"", "+", "policy", ".", "getPolicyAuthor", "(", ")", "+", "\",", "\"", "+", "policy", ".", "getPolicyVersion", "(", ")", "+", "\">\"", ";", "}", "}", "</s>" ]
9,102
[ "<s>", "package", "com", ".", "smartgrid", ".", "app", ";", "public", "abstract", "class", "CustomMessage", "{", "}", "</s>" ]
9,103
[ "<s>", "package", "com", ".", "smartgrid", ".", "app", ";", "import", "java", ".", "sql", ".", "Connection", ";", "import", "java", ".", "sql", ".", "DriverManager", ";", "import", "java", ".", "sql", ".", "SQLException", ";", "import", "java", ".", "sql", ".", "Statement", ";", "import", "java", ".", "sql", ".", "Timestamp", ";", "import", "java", ".", "util", ".", "Date", ";", "public", "class", "Logger", "{", "private", "Connection", "con", ";", "private", "String", "connectionURL", ";", "private", "Statement", "stmt", ";", "public", "Logger", "(", ")", "{", "con", "=", "null", ";", "stmt", "=", "null", ";", "connectionURL", "=", "\"\"", "+", "\"\"", ";", "}", "public", "Logger", "(", "String", "hostname", ",", "String", "database", ",", "String", "username", ",", "String", "password", ")", "{", "con", "=", "null", ";", "stmt", "=", "null", ";", "this", ".", "connectionURL", "=", "\"\"", "+", "hostname", "+", "\"/\"", "+", "database", "+", "\"?\"", "+", "\"user=\"", "+", "username", "+", "\"&password=\"", "+", "password", ";", "}", "public", "boolean", "open", "(", ")", "{", "try", "{", "con", "=", "DriverManager", ".", "getConnection", "(", "connectionURL", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ".", "toString", "(", ")", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "-", "1", ")", ";", "}", "try", "{", "stmt", "=", "con", ".", "createStatement", "(", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ".", "toString", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ".", "toString", "(", ")", ")", ";", "}", "createTables", "(", ")", ";", "return", "true", ";", "}", "public", "void", "close", "(", ")", "{", "try", "{", "con", ".", "close", "(", ")", ";", "stmt", ".", "close", "(", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ".", "toString", "(", ")", ")", ";", "}", "}", "private", "void", "createTables", "(", ")", "{", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ";", "executeUpdate", "(", "query", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ";", "executeUpdate", "(", "query", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ";", "executeUpdate", "(", "query", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ";", "executeUpdate", "(", "query", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ";", "executeUpdate", "(", "query", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ";", "executeUpdate", "(", "query", ")", ";", "}", "private", "boolean", "executeUpdate", "(", "String", "query", ")", "{", "try", "{", "stmt", ".", "executeUpdate", "(", "query", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ".", "toString", "(", ")", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "-", "1", ")", ";", "}", "return", "true", ";", "}", "public", "boolean", "logAggregatorPolicy", "(", "String", "author", ",", "String", "name", ",", "double", "version", ")", "{", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "\"'\"", "+", "author", "+", "\"',\"", "+", "\"'\"", "+", "name", "+", "\"',\"", "+", "version", "+", "\"\"", "+", "\"", "author", "=", "'\"", "+", "author", "+", "\"\"", "+", "name", "+", "\"\"", "+", "version", "+", "\"')\"", "+", "\";\"", ";", "if", "(", "executeUpdate", "(", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "public", "boolean", "logAggregator", "(", "Date", "tick", ",", "double", "supply", ",", "double", "overallDemand", ",", "double", "price", ")", "{", "Timestamp", "tstamp", "=", "new", "Timestamp", "(", "tick", ".", "getTime", "(", ")", ")", ";", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\",'\"", "+", "tstamp", ".", "toString", "(", ")", "+", "\"',\"", "+", "supply", "+", "\",\"", "+", "overallDemand", "+", "\",\"", "+", "price", "+", "\");\"", ";", "if", "(", "executeUpdate", "(", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "public", "boolean", "logHouseholdPolicy", "(", "String", "author", ",", "String", "name", ",", "double", "version", ")", "{", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "\"'\"", "+", "author", "+", "\"',\"", "+", "\"'\"", "+", "name", "+", "\"',\"", "+", "version", "+", "\"\"", "+", "\"", "author", "=", "'\"", "+", "author", "+", "\"\"", "+", "name", "+", "\"\"", "+", "version", "+", "\"')\"", "+", "\";\"", ";", "if", "(", "executeUpdate", "(", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "public", "boolean", "logHouseholdDemand", "(", "long", "householdID", ",", "Date", "tick", ",", "double", "demand", ",", "int", "appliancesOn", ")", "{", "Timestamp", "tstamp", "=", "new", "Timestamp", "(", "tick", ".", "getTime", "(", ")", ")", ";", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "householdID", "+", "\",\"", "+", "\"\"", "+", "\",'\"", "+", "tstamp", ".", "toString", "(", ")", "+", "\"',\"", "+", "demand", "+", "\",\"", "+", "appliancesOn", "+", "\");\"", ";", "if", "(", "executeUpdate", "(", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "public", "boolean", "logRun", "(", ")", "{", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\");\"", ";", "if", "(", "executeUpdate", "(", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "public", "boolean", "logRunHouseholdConnection", "(", "long", "household_id", ",", "String", "author", ",", "String", "name", ",", "double", "version", ")", "{", "String", "query", "=", "new", "String", "(", ")", ";", "query", "=", "\"\"", "+", "\"\"", "+", "\",\"", "+", "household_id", "+", "\",\"", "+", "\"\"", "+", "\"", "author", "=", "'\"", "+", "author", "+", "\"\"", "+", "name", "+", "\"\"", "+", "version", "+", "\"')\"", "+", "\");\"", ";", "if", "(", "executeUpdate", "(", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "}", "</s>" ]
9,104
[ "<s>", "package", "com", ".", "smartgrid", ".", "messenger", ";", "import", "com", ".", "smartgrid", ".", "messenger", ".", "MessengerBasic", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "junit", ".", "framework", ".", "Test", ";", "import", "junit", ".", "framework", ".", "TestCase", ";", "import", "junit", ".", "framework", ".", "TestSuite", ";", "class", "Person", "{", "private", "String", "name", ";", "public", "Person", "(", "String", "s", ")", "{", "name", "=", "s", ";", "}", "public", "Integer", "anounce", "(", "String", "s", ")", "{", "return", "1", ";", "}", "public", "Integer", "whats_one_plus_one", "(", ")", "{", "return", "2", ";", "}", "public", "boolean", "am_i_happy", "(", ")", "{", "return", "true", ";", "}", "}", "public", "class", "MessengerBasicTest", "extends", "TestCase", "{", "private", "Map", "<", "Integer", ",", "Object", ">", "members", ";", "Messenger", "<", "Person", ">", "messenger", ";", "public", "MessengerBasicTest", "(", "String", "testName", ")", "{", "super", "(", "testName", ")", ";", "}", "public", "static", "Test", "suite", "(", ")", "{", "return", "new", "TestSuite", "(", "MessengerBasicTest", ".", "class", ")", ";", "}", "public", "void", "setUp", "(", ")", "{", "members", "=", "new", "HashMap", "<", "Integer", ",", "Object", ">", "(", ")", ";", "members", ".", "put", "(", "1", ",", "(", "Object", ")", "new", "Person", "(", "\"Bob\"", ")", ")", ";", "messenger", "=", "new", "MessengerBasic", "(", "members", ")", ";", "}", "public", "void", "testMessageOne", "(", ")", "{", "Integer", "i", "=", "messenger", ".", "<", "Integer", ",", "String", ">", "message", "(", "1", ",", "new", "Message", "<", "String", ">", "(", "\"anounce\"", ",", "\"Hello", "World\"", ")", ")", ";", "assertTrue", "(", "i", "==", "1", ")", ";", "}", "public", "void", "testMessageNoParameters", "(", ")", "{", "Integer", "i", "=", "messenger", ".", "<", "Integer", ",", "Void", ">", "message", "(", "1", ",", "new", "Message", "<", "Void", ">", "(", "\"\"", ",", "null", ")", ")", ";", "assertTrue", "(", "i", "==", "2", ")", ";", "}", "public", "void", "testMessageBooleanReturnType", "(", ")", "{", "}", "public", "void", "testMapReturnType", "(", ")", "{", "}", "public", "void", "testMessageMany", "(", ")", "{", "Map", "<", "Integer", ",", "Person", ">", "many_members", "=", "new", "HashMap", "<", "Integer", ",", "Person", ">", "(", ")", ";", "for", "(", "Integer", "i", "=", "0", ";", "i", "<", "200", ";", "i", "++", ")", "{", "many_members", ".", "put", "(", "i", ",", "new", "Person", "(", "i", ".", "toString", "(", ")", ")", ")", ";", "}", "Messenger", "<", "Person", ">", "messenger_with_many", "=", "new", "MessengerBasic", "<", "Person", ">", "(", "many_members", ")", ";", "Integer", "[", "]", "member_ids", "=", "many_members", ".", "keySet", "(", ")", ".", "<", "Integer", ">", "toArray", "(", "new", "Integer", "[", "0", "]", ")", ";", "Map", "<", "Integer", ",", "Integer", ">", "response", "=", "messenger_with_many", ".", "<", "Integer", ",", "String", ">", "messageMany", "(", "member_ids", ",", "new", "Message", "<", "String", ">", "(", "\"anounce\"", ",", "\"Hello", "World\"", ")", ")", ";", "for", "(", "Integer", "i", "=", "0", ";", "i", "<", "200", ";", "i", "++", ")", "{", "assertTrue", "(", "response", ".", "get", "(", "i", ")", "==", "1", ")", ";", "}", "}", "}", "</s>" ]
9,105
[ "<s>", "package", "com", ".", "smartgrid", ".", "app", ";", "import", "junit", ".", "framework", ".", "Test", ";", "import", "junit", ".", "framework", ".", "TestCase", ";", "import", "junit", ".", "framework", ".", "TestSuite", ";", "public", "class", "AppTest", "extends", "TestCase", "{", "public", "AppTest", "(", "String", "testName", ")", "{", "super", "(", "testName", ")", ";", "}", "public", "static", "Test", "suite", "(", ")", "{", "return", "new", "TestSuite", "(", "AppTest", ".", "class", ")", ";", "}", "public", "void", "testApp", "(", ")", "{", "assertTrue", "(", "true", ")", ";", "}", "}", "</s>" ]
9,106
[ "<s>", "package", "arch", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createAtom", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createLiteral", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createNumber", ";", "import", "jason", ".", "JasonException", ";", "import", "jason", ".", "ReceiverNotFoundException", ";", "import", "jason", ".", "RevisionFailedException", ";", "import", "jason", ".", "asSemantics", ".", "Intention", ";", "import", "jason", ".", "asSemantics", ".", "Message", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "Atom", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "asSyntax", ".", "LiteralImpl", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Structure", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "jason", ".", "mas2j", ".", "ClassParameters", ";", "import", "jason", ".", "runtime", ".", "Settings", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Queue", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "java", ".", "util", ".", "concurrent", ".", "LinkedBlockingQueue", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ScheduledExecutorService", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ScheduledThreadPoolExecutor", ";", "import", "java", ".", "util", ".", "concurrent", ".", "TimeUnit", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "jia", ".", "cluster", ";", "import", "jmoise", ".", "OrgAgent", ";", "import", "agent", ".", "SelectEvent", ";", "import", "env", ".", "WorldModel", ";", "import", "env", ".", "WorldView", ";", "import", "env", ".", "WorldModel", ".", "Move", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "CowModelFactory", ";", "import", "env", ".", "IClusterModel", ";", "import", "env", ".", "ICowModel", ";", "import", "env", ".", "Cow", ";", "import", "env", ".", "ClusterModel", ";", "public", "class", "CowboyArch", "extends", "OrgAgent", "{", "LocalWorldModel", "model", "=", "null", ";", "WorldView", "view", "=", "null", ";", "ICowModel", "cModel", "=", "null", ";", "IClusterModel", "clModel", "=", "null", ";", "String", "simId", "=", "null", ";", "int", "myId", "=", "-", "1", ";", "boolean", "gui", "=", "false", ";", "boolean", "playing", "=", "false", ";", "String", "massimBackDir", "=", "null", ";", "String", "teamId", "=", "null", ";", "Map", "<", "Integer", ",", "Integer", ">", "lastSeen", "=", "new", "HashMap", "<", "Integer", ",", "Integer", ">", "(", ")", ";", "int", "simStep", "=", "0", ";", "WriteStatusThread", "writeStatusThread", "=", "null", ";", "protected", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "CowboyArch", ".", "class", ".", "getName", "(", ")", ")", ";", "public", "static", "Atom", "aOBSTACLE", "=", "new", "Atom", "(", "\"obstacle\"", ")", ";", "public", "static", "Atom", "aENEMY", "=", "new", "Atom", "(", "\"enemy\"", ")", ";", "public", "static", "Atom", "aENEMYCORRAL", "=", "new", "Atom", "(", "\"enemycorral\"", ")", ";", "public", "static", "Atom", "aALLY", "=", "new", "Atom", "(", "\"ally\"", ")", ";", "public", "static", "Atom", "aEMPTY", "=", "new", "Atom", "(", "\"empty\"", ")", ";", "public", "static", "Atom", "aSWITCH", "=", "new", "Atom", "(", "\"switch\"", ")", ";", "public", "static", "Atom", "aFENCE", "=", "new", "Atom", "(", "\"fence\"", ")", ";", "public", "static", "Atom", "aOPEN", "=", "new", "Atom", "(", "\"open\"", ")", ";", "public", "static", "Atom", "aCLOSED", "=", "new", "Atom", "(", "\"closed\"", ")", ";", "@", "Override", "public", "void", "initAg", "(", "String", "agClass", ",", "ClassParameters", "bbPars", ",", "String", "asSrc", ",", "Settings", "stts", ")", "throws", "JasonException", "{", "super", ".", "initAg", "(", "agClass", ",", "bbPars", ",", "asSrc", ",", "stts", ")", ";", "gui", "=", "\"yes\"", ".", "equals", "(", "stts", ".", "getUserParameter", "(", "\"gui\"", ")", ")", ";", "if", "(", "getMyId", "(", ")", "==", "0", ")", "gui", "=", "true", ";", "boolean", "writeStatus", "=", "\"yes\"", ".", "equals", "(", "stts", ".", "getUserParameter", "(", "\"write_status\"", ")", ")", ";", "boolean", "dumpAgsMind", "=", "\"yes\"", ".", "equals", "(", "stts", ".", "getUserParameter", "(", "\"\"", ")", ")", ";", "if", "(", "writeStatus", "||", "dumpAgsMind", ")", "writeStatusThread", "=", "WriteStatusThread", ".", "create", "(", "this", ",", "writeStatus", ",", "dumpAgsMind", ")", ";", "teamId", "=", "stts", ".", "getUserParameter", "(", "\"teamid\"", ")", ";", "if", "(", "teamId", "==", "null", ")", "logger", ".", "info", "(", "\"\"", ")", ";", "else", "if", "(", "teamId", ".", "startsWith", "(", "\"\"", ")", ")", "teamId", "=", "teamId", ".", "substring", "(", "1", ",", "teamId", ".", "length", "(", ")", "-", "1", ")", ";", "WriteStatusThread", ".", "registerAgent", "(", "getAgName", "(", ")", ",", "this", ")", ";", "massimBackDir", "=", "stts", ".", "getUserParameter", "(", "\"\"", ")", ";", "if", "(", "massimBackDir", "!=", "null", "&&", "massimBackDir", ".", "startsWith", "(", "\"\\\"\"", ")", ")", "massimBackDir", "=", "massimBackDir", ".", "substring", "(", "1", ",", "massimBackDir", ".", "length", "(", ")", "-", "1", ")", ";", "logger", "=", "Logger", ".", "getLogger", "(", "CowboyArch", ".", "class", ".", "getName", "(", ")", "+", "\".CA-\"", "+", "getAgName", "(", ")", ")", ";", "setCheckCommunicationLink", "(", "false", ")", ";", "initialBeliefs", "(", ")", ";", "}", "void", "initialBeliefs", "(", ")", "throws", "RevisionFailedException", "{", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"team_size\"", ",", "createNumber", "(", "WorldModel", ".", "agsByTeam", ")", ")", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<=", "WorldModel", ".", "agsByTeam", ";", "i", "++", ")", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"agent_id\"", ",", "createAtom", "(", "teamId", "+", "i", ")", ",", "createNumber", "(", "i", ")", ")", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"cows_by_boy\"", ",", "createNumber", "(", "cluster", ".", "COWS_BY_BOY", ")", ")", ")", ";", "}", "@", "Override", "public", "void", "stopAg", "(", ")", "{", "if", "(", "view", "!=", "null", ")", "view", ".", "dispose", "(", ")", ";", "if", "(", "writeStatusThread", "!=", "null", ")", "writeStatusThread", ".", "interrupt", "(", ")", ";", "super", ".", "stopAg", "(", ")", ";", "}", "void", "setSimId", "(", "String", "id", ")", "{", "simId", "=", "id", ";", "}", "public", "String", "getSimId", "(", ")", "{", "return", "simId", ";", "}", "public", "boolean", "hasGUI", "(", ")", "{", "return", "gui", ";", "}", "public", "int", "getMyId", "(", ")", "{", "if", "(", "myId", "<", "0", ")", "myId", "=", "getAgId", "(", "getAgName", "(", ")", ")", ";", "return", "myId", ";", "}", "public", "LocalWorldModel", "getModel", "(", ")", "{", "return", "model", ";", "}", "void", "gsizePerceived", "(", "int", "w", ",", "int", "h", ",", "String", "opponent", ")", "throws", "RevisionFailedException", "{", "model", "=", "new", "LocalWorldModel", "(", "w", ",", "h", ",", "WorldModel", ".", "agsByTeam", ",", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "getBB", "(", ")", ")", ";", "model", ".", "setOpponent", "(", "opponent", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "Literal", ".", "parseLiteral", "(", "\"gsize(\"", "+", "w", "+", "\",\"", "+", "h", "+", "\")\"", ")", ")", ";", "playing", "=", "true", ";", "cModel", "=", "CowModelFactory", ".", "getModel", "(", "teamId", "+", "myId", ")", ";", "cModel", ".", "setSize", "(", "w", ",", "h", ")", ";", "clModel", "=", "ClusterModelFactory", ".", "getModel", "(", "teamId", "+", "myId", ")", ";", "clModel", ".", "setStepcl", "(", "-", "1", ")", ";", "if", "(", "view", "!=", "null", ")", "view", ".", "dispose", "(", ")", ";", "if", "(", "gui", ")", "{", "try", "{", "view", "=", "new", "WorldView", "(", "\"\"", "+", "(", "getMyId", "(", ")", "+", "1", ")", "+", "\"\"", "+", "opponent", ",", "model", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "if", "(", "writeStatusThread", "!=", "null", ")", "writeStatusThread", ".", "reset", "(", ")", ";", "}", "void", "corralPerceived", "(", "Location", "upperLeft", ",", "Location", "downRight", ")", "throws", "RevisionFailedException", "{", "model", ".", "setCorral", "(", "upperLeft", ",", "downRight", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"corral\"", ",", "createNumber", "(", "upperLeft", ".", "x", ")", ",", "createNumber", "(", "upperLeft", ".", "y", ")", ",", "createNumber", "(", "downRight", ".", "x", ")", ",", "createNumber", "(", "downRight", ".", "y", ")", ")", ")", ";", "}", "void", "stepsPerceived", "(", "int", "s", ")", "throws", "RevisionFailedException", "{", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"steps\"", ",", "createNumber", "(", "s", ")", ")", ")", ";", "model", ".", "setMaxSteps", "(", "s", ")", ";", "model", ".", "restoreObstaclesFromFile", "(", "this", ")", ";", "model", ".", "createStoreObsThread", "(", "this", ")", ";", "}", "public", "void", "cowPerceived", "(", "int", "cowId", ",", "int", "x", ",", "int", "y", ")", "{", "Location", "c", "=", "new", "Location", "(", "x", ",", "y", ")", ";", "if", "(", "model", ".", "getCorral", "(", ")", ".", "contains", "(", "c", ")", ")", "{", "}", "else", "{", "lastSeen", ".", "put", "(", "cowId", ",", "getSimStep", "(", ")", ")", ";", "cModel", ".", "insertCow", "(", "cowId", ",", "x", ",", "y", ",", "getSimStep", "(", ")", ")", ";", "}", "}", "public", "Cow", "[", "]", "getPerceivedCows", "(", ")", "{", "return", "cModel", ".", "getCows", "(", ")", ";", "}", "public", "int", "getLastSeenCow", "(", "int", "cow", ")", "{", "return", "lastSeen", ".", "get", "(", "cow", ")", ";", "}", "public", "void", "obstaclePerceived", "(", "int", "x", ",", "int", "y", ")", "{", "if", "(", "!", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "x", ",", "y", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "x", ",", "y", ")", ";", "Message", "m", "=", "new", "Message", "(", "\"tell\"", ",", "null", ",", "null", ",", "createCellPerception", "(", "x", ",", "y", ",", "aOBSTACLE", ")", ")", ";", "try", "{", "broadcast", "(", "m", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "else", "{", "Location", "l", "=", "new", "Location", "(", "x", ",", "y", ")", ";", "if", "(", "ephemeralObstacle", ".", "remove", "(", "l", ")", ")", "logger", ".", "info", "(", "\"\"", "+", "l", "+", "\"\"", ")", ";", "}", "if", "(", "clModel", "==", "null", ")", "clModel", "=", "ClusterModelFactory", ".", "getModel", "(", "teamId", "+", "myId", ")", ";", "clModel", ".", "insertTree", "(", "x", ",", "y", ")", ";", "}", "public", "void", "enemyCorralPerceived", "(", "int", "x", ",", "int", "y", ")", "{", "if", "(", "!", "model", ".", "hasObject", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "x", ",", "y", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "x", ",", "y", ")", ";", "Message", "m", "=", "new", "Message", "(", "\"tell\"", ",", "null", ",", "null", ",", "createCellPerception", "(", "x", ",", "y", ",", "aENEMYCORRAL", ")", ")", ";", "try", "{", "broadcast", "(", "m", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "public", "void", "fencePerceived", "(", "int", "x", ",", "int", "y", ",", "boolean", "open", ")", "{", "int", "obj", ";", "Atom", "s", ";", "if", "(", "open", ")", "{", "obj", "=", "WorldModel", ".", "OPEN_FENCE", ";", "s", "=", "aOPEN", ";", "}", "else", "{", "obj", "=", "WorldModel", ".", "CLOSED_FENCE", ";", "s", "=", "aCLOSED", ";", "}", "if", "(", "!", "model", ".", "hasObject", "(", "obj", ",", "x", ",", "y", ")", ")", "{", "model", ".", "add", "(", "obj", ",", "x", ",", "y", ")", ";", "Message", "m", "=", "new", "Message", "(", "\"tell\"", ",", "null", ",", "null", ",", "createCellPerception", "(", "x", ",", "y", ",", "ASSyntax", ".", "createStructure", "(", "aFENCE", ".", "toString", "(", ")", ",", "s", ")", ")", ")", ";", "try", "{", "broadcast", "(", "m", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "public", "void", "switchPerceived", "(", "int", "x", ",", "int", "y", ")", "throws", "RevisionFailedException", "{", "if", "(", "!", "model", ".", "hasObject", "(", "WorldModel", ".", "SWITCH", ",", "x", ",", "y", ")", ")", "{", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"switch\"", ",", "createNumber", "(", "x", ")", ",", "createNumber", "(", "y", ")", ")", ")", ";", "Message", "m", "=", "new", "Message", "(", "\"tell\"", ",", "null", ",", "null", ",", "createCellPerception", "(", "x", ",", "y", ",", "aSWITCH", ")", ")", ";", "try", "{", "broadcast", "(", "m", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "model", ".", "add", "(", "WorldModel", ".", "SWITCH", ",", "x", ",", "y", ")", ";", "}", "public", "void", "lineOfSightPerceived", "(", "int", "line", ")", "throws", "RevisionFailedException", "{", "model", ".", "setAgPerceptionRatio", "(", "line", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"\"", ",", "createNumber", "(", "line", ")", ")", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"\"", ",", "createNumber", "(", "WorldModel", ".", "cowPerceptionRatio", ")", ")", ")", ";", "}", "private", "static", "final", "int", "lastRecordCapacity", "=", "12", ";", "Queue", "<", "Location", ">", "lastLocations", "=", "new", "LinkedBlockingQueue", "<", "Location", ">", "(", "lastRecordCapacity", ")", ";", "Queue", "<", "Move", ">", "lastActions", "=", "new", "LinkedBlockingQueue", "<", "Move", ">", "(", "lastRecordCapacity", ")", ";", "Set", "<", "Location", ">", "ephemeralObstacle", "=", "new", "HashSet", "<", "Location", ">", "(", ")", ";", "ScheduledExecutorService", "schedule", "=", "new", "ScheduledThreadPoolExecutor", "(", "30", ")", ";", "private", "static", "<", "T", ">", "void", "myAddQueue", "(", "Queue", "<", "T", ">", "q", ",", "T", "e", ")", "{", "if", "(", "!", "q", ".", "offer", "(", "e", ")", ")", "{", "q", ".", "poll", "(", ")", ";", "q", ".", "offer", "(", "e", ")", ";", "}", "}", "private", "static", "<", "T", ">", "boolean", "allEquals", "(", "Queue", "<", "T", ">", "q", ")", "{", "if", "(", "q", ".", "size", "(", ")", "+", "1", "<", "lastRecordCapacity", ")", "return", "false", ";", "Iterator", "<", "T", ">", "il", "=", "q", ".", "iterator", "(", ")", ";", "if", "(", "il", ".", "hasNext", "(", ")", ")", "{", "T", "first", "=", "il", ".", "next", "(", ")", ";", "while", "(", "il", ".", "hasNext", "(", ")", ")", "{", "T", "other", "=", "il", ".", "next", "(", ")", ";", "if", "(", "!", "first", ".", "equals", "(", "other", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}", "public", "boolean", "isEphemeralObstacle", "(", "Location", "l", ")", "{", "return", "ephemeralObstacle", ".", "contains", "(", "l", ")", ";", "}", "Location", "oldLoc", ";", "public", "Location", "getLastLocation", "(", ")", "{", "return", "oldLoc", ";", "}", "public", "Queue", "<", "Location", ">", "getLastLocations", "(", ")", "{", "return", "lastLocations", ";", "}", "protected", "String", "lastAct", ";", "protected", "void", "setLastAct", "(", "String", "act", ")", "{", "lastAct", "=", "act", ";", "if", "(", "act", "!=", "null", ")", "myAddQueue", "(", "lastActions", ",", "Move", ".", "valueOf", "(", "act", ")", ")", ";", "}", "public", "String", "getLastAction", "(", ")", "{", "return", "lastAct", ";", "}", "public", "int", "getSimStep", "(", ")", "{", "return", "simStep", ";", "}", "void", "locationPerceived", "(", "final", "int", "x", ",", "final", "int", "y", ")", "{", "if", "(", "model", "==", "null", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "return", ";", "}", "oldLoc", "=", "model", ".", "getAgPos", "(", "getMyId", "(", ")", ")", ";", "if", "(", "oldLoc", "!=", "null", ")", "{", "model", ".", "clearAgView", "(", "oldLoc", ")", ";", "}", "if", "(", "oldLoc", "==", "null", "||", "!", "oldLoc", ".", "equals", "(", "new", "Location", "(", "x", ",", "y", ")", ")", ")", "{", "try", "{", "model", ".", "setAgPos", "(", "getMyId", "(", ")", ",", "x", ",", "y", ")", ";", "model", ".", "incVisited", "(", "x", ",", "y", ")", ";", "Message", "m", "=", "new", "Message", "(", "\"tell\"", ",", "null", ",", "null", ",", "\"my_status(\"", "+", "x", "+", "\",\"", "+", "y", "+", "\")\"", ")", ";", "broadcast", "(", "m", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "myAddQueue", "(", "lastLocations", ",", "new", "Location", "(", "x", ",", "y", ")", ")", ";", "checkRestart", "(", ")", ";", "}", "protected", "void", "checkRestart", "(", ")", "{", "if", "(", "allEquals", "(", "lastLocations", ")", ")", "{", "try", "{", "logger", ".", "info", "(", "\"\"", "+", "getAgName", "(", ")", "+", "\"\"", "+", "lastLocations", ")", ";", "getTS", "(", ")", ".", "getC", "(", ")", ".", "addAchvGoal", "(", "new", "LiteralImpl", "(", "\"restart\"", ")", ",", "Intention", ".", "EmptyInt", ")", ";", "lastLocations", ".", "clear", "(", ")", ";", "lastSeen", ".", "clear", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "e", ")", ";", "}", "if", "(", "allEquals", "(", "lastActions", ")", "&&", "lastActions", ".", "iterator", "(", ")", ".", "next", "(", ")", "!=", "Move", ".", "skip", ")", "{", "final", "Location", "newLoc", "=", "WorldModel", ".", "getNewLocationForAction", "(", "getLastLocation", "(", ")", ",", "lastActions", ".", "peek", "(", ")", ")", ";", "if", "(", "newLoc", "!=", "null", "&&", "!", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "newLoc", ")", ")", "{", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "newLoc", ")", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "getAgName", "(", ")", "+", "\"\"", "+", "lastActions", ")", ";", "getTS", "(", ")", ".", "getC", "(", ")", ".", "addAchvGoal", "(", "new", "LiteralImpl", "(", "\"\"", ")", ",", "Intention", ".", "EmptyInt", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"\"", "+", "newLoc", "+", "\"\"", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "newLoc", ")", ";", "ephemeralObstacle", ".", "add", "(", "newLoc", ")", ";", "schedule", ".", "schedule", "(", "new", "Runnable", "(", ")", "{", "public", "void", "run", "(", ")", "{", "if", "(", "ephemeralObstacle", ".", "contains", "(", "newLoc", ")", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "newLoc", ")", ";", "model", ".", "remove", "(", "WorldModel", ".", "OBSTACLE", ",", "newLoc", ")", ";", "}", "}", "}", ",", "10", ",", "TimeUnit", ".", "SECONDS", ")", ";", "}", "}", "}", "}", "}", "public", "static", "Literal", "createCellPerception", "(", "int", "x", ",", "int", "y", ",", "Term", "obj", ")", "{", "return", "createLiteral", "(", "\"cell\"", ",", "createNumber", "(", "x", ")", ",", "createNumber", "(", "y", ")", ",", "obj", ")", ";", "}", "void", "initKnownCows", "(", ")", "{", "model", ".", "clearKnownCows", "(", ")", ";", "}", "void", "enemyPerceived", "(", "int", "x", ",", "int", "y", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "ENEMY", ",", "x", ",", "y", ")", ";", "}", "void", "simulationEndPerceived", "(", "String", "result", ")", "throws", "RevisionFailedException", "{", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "Literal", ".", "parseLiteral", "(", "\"\"", "+", "result", "+", "\")\"", ")", ")", ";", "model", "=", "null", ";", "playing", "=", "false", ";", "lastSeen", ".", "clear", "(", ")", ";", "if", "(", "view", "!=", "null", ")", "view", ".", "dispose", "(", ")", ";", "cModel", ".", "reset", "(", ")", ";", "}", "void", "setSimStep", "(", "int", "s", ")", "{", "(", "(", "SelectEvent", ")", "getTS", "(", ")", ".", "getAg", "(", ")", ")", ".", "cleanCows", "(", ")", ";", "simStep", "=", "s", ";", "super", ".", "setCycleNumber", "(", "simStep", ")", ";", "if", "(", "view", "!=", "null", ")", "view", ".", "setCycle", "(", "simStep", ")", ";", "if", "(", "writeStatusThread", "!=", "null", ")", "writeStatusThread", ".", "go", "(", ")", ";", "}", "void", "setScore", "(", "int", "s", ")", "{", "model", ".", "setCowsBlue", "(", "s", ")", ";", "}", "@", "Override", "public", "void", "broadcast", "(", "Message", "m", ")", "throws", "Exception", "{", "if", "(", "model", "==", "null", ")", "return", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<=", "model", ".", "getAgsByTeam", "(", ")", ";", "i", "++", ")", "{", "String", "oname", "=", "teamId", "+", "i", ";", "if", "(", "!", "getAgName", "(", ")", ".", "equals", "(", "oname", ")", ")", "{", "Message", "msg", "=", "new", "Message", "(", "m", ")", ";", "msg", ".", "setReceiver", "(", "oname", ")", ";", "for", "(", "int", "t", "=", "0", ";", "t", "<", "6", ";", "t", "++", ")", "{", "try", "{", "sendMsg", "(", "msg", ")", ";", "break", ";", "}", "catch", "(", "ReceiverNotFoundException", "e", ")", "{", "logger", ".", "info", "(", "\"Receiver", "\"", "+", "oname", "+", "\"\"", "+", "t", ")", ";", "Thread", ".", "sleep", "(", "500", ")", ";", "}", "}", "}", "}", "}", "@", "Override", "public", "void", "checkMail", "(", ")", "{", "super", ".", "checkMail", "(", ")", ";", "Iterator", "<", "Message", ">", "im", "=", "getTS", "(", ")", ".", "getC", "(", ")", ".", "getMailBox", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "im", ".", "hasNext", "(", ")", ")", "{", "Message", "m", "=", "im", ".", "next", "(", ")", ";", "try", "{", "if", "(", "m", ".", "getIlForce", "(", ")", ".", "equals", "(", "\"tell-cows\"", ")", ")", "{", "im", ".", "remove", "(", ")", ";", "}", "else", "{", "String", "ms", "=", "m", ".", "getPropCont", "(", ")", ".", "toString", "(", ")", ";", "if", "(", "ms", ".", "startsWith", "(", "\"cell\"", ")", "&&", "model", "!=", "null", ")", "{", "im", ".", "remove", "(", ")", ";", "Literal", "p", "=", "(", "Literal", ")", "m", ".", "getPropCont", "(", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "p", ".", "getTerm", "(", "0", ")", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "p", ".", "getTerm", "(", "1", ")", ")", ".", "solve", "(", ")", ";", "if", "(", "model", ".", "inGrid", "(", "x", ",", "y", ")", ")", "{", "if", "(", "p", ".", "getTerm", "(", "2", ")", ".", "equals", "(", "aOBSTACLE", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "x", ",", "y", ")", ";", "}", "else", "if", "(", "p", ".", "getTerm", "(", "2", ")", ".", "equals", "(", "aENEMYCORRAL", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "x", ",", "y", ")", ";", "}", "else", "if", "(", "p", ".", "getTerm", "(", "2", ")", ".", "equals", "(", "aSWITCH", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "SWITCH", ",", "x", ",", "y", ")", ";", "Literal", "l", "=", "createLiteral", "(", "\"switch\"", ",", "createNumber", "(", "x", ")", ",", "createNumber", "(", "y", ")", ")", ";", "l", ".", "addSource", "(", "createAtom", "(", "m", ".", "getSender", "(", ")", ")", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "l", ")", ";", "}", "else", "if", "(", "p", ".", "getTerm", "(", "2", ")", ".", "toString", "(", ")", ".", "startsWith", "(", "aFENCE", ".", "toString", "(", ")", ")", ")", "{", "Structure", "s", "=", "(", "Structure", ")", "p", ".", "getTerm", "(", "2", ")", ";", "if", "(", "s", ".", "getTerm", "(", "0", ")", ".", "equals", "(", "aOPEN", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "OPEN_FENCE", ",", "x", ",", "y", ")", ";", "}", "else", "if", "(", "s", ".", "getTerm", "(", "0", ")", ".", "equals", "(", "aCLOSED", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "x", ",", "y", ")", ";", "}", "}", "}", "}", "else", "if", "(", "ms", ".", "startsWith", "(", "\"my_status\"", ")", "&&", "model", "!=", "null", ")", "{", "im", ".", "remove", "(", ")", ";", "Literal", "p", "=", "Literal", ".", "parseLiteral", "(", "m", ".", "getPropCont", "(", ")", ".", "toString", "(", ")", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "p", ".", "getTerm", "(", "0", ")", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "p", ".", "getTerm", "(", "1", ")", ")", ".", "solve", "(", ")", ";", "if", "(", "model", ".", "inGrid", "(", "x", ",", "y", ")", ")", "{", "try", "{", "int", "agid", "=", "getAgId", "(", "m", ".", "getSender", "(", ")", ")", ";", "model", ".", "setAgPos", "(", "agid", ",", "x", ",", "y", ")", ";", "model", ".", "incVisited", "(", "x", ",", "y", ")", ";", "Literal", "tAlly", "=", "createLiteral", "(", "\"ally_pos\"", ",", "new", "Atom", "(", "m", ".", "getSender", "(", ")", ")", ",", "createNumber", "(", "x", ")", ",", "createNumber", "(", "y", ")", ")", ";", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "tAlly", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "}", "public", "static", "int", "getAgId", "(", "String", "agName", ")", "{", "boolean", "nbWith2Digits", "=", "Character", ".", "isDigit", "(", "agName", ".", "charAt", "(", "agName", ".", "length", "(", ")", "-", "2", ")", ")", ";", "if", "(", "nbWith2Digits", ")", "return", "(", "Integer", ".", "parseInt", "(", "agName", ".", "substring", "(", "agName", ".", "length", "(", ")", "-", "2", ")", ")", ")", "-", "1", ";", "else", "return", "(", "Integer", ".", "parseInt", "(", "agName", ".", "substring", "(", "agName", ".", "length", "(", ")", "-", "1", ")", ")", ")", "-", "1", ";", "}", "public", "ICowModel", "getCowModel", "(", ")", "{", "return", "cModel", ";", "}", "}", "</s>" ]
9,107
[ "<s>", "package", "arch", ";", "import", "java", ".", "io", ".", "ByteArrayInputStream", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "OutputStream", ";", "import", "java", ".", "net", ".", "Socket", ";", "import", "java", ".", "net", ".", "SocketException", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilderFactory", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "ParserConfigurationException", ";", "import", "javax", ".", "xml", ".", "transform", ".", "TransformerConfigurationException", ";", "import", "javax", ".", "xml", ".", "transform", ".", "TransformerException", ";", "import", "javax", ".", "xml", ".", "transform", ".", "TransformerFactory", ";", "import", "javax", ".", "xml", ".", "transform", ".", "dom", ".", "DOMSource", ";", "import", "javax", ".", "xml", ".", "transform", ".", "stream", ".", "StreamResult", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Document", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Element", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Node", ";", "import", "org", ".", "w3c", ".", "dom", ".", "NodeList", ";", "import", "org", ".", "xml", ".", "sax", ".", "SAXException", ";", "public", "abstract", "class", "ACAgent", "{", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "ACAgent", ".", "class", ".", "getName", "(", ")", ")", ";", "@", "SuppressWarnings", "(", "\"serial\"", ")", "private", "class", "SocketClosedException", "extends", "Exception", "{", "}", "private", "int", "networkport", ";", "private", "String", "networkhost", ";", "private", "Socket", "socket", ";", "private", "InputStream", "inputstream", ";", "private", "OutputStream", "outputstream", ";", "private", "String", "username", ";", "private", "String", "password", ";", "private", "DocumentBuilderFactory", "documentbuilderfactory", ";", "private", "TransformerFactory", "transformerfactory", ";", "private", "boolean", "connected", "=", "false", ";", "public", "ACAgent", "(", ")", "{", "networkhost", "=", "\"localhost\"", ";", "networkport", "=", "0", ";", "documentbuilderfactory", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ";", "transformerfactory", "=", "TransformerFactory", ".", "newInstance", "(", ")", ";", "}", "public", "String", "getHost", "(", ")", "{", "return", "networkhost", ";", "}", "public", "void", "setHost", "(", "String", "host", ")", "{", "this", ".", "networkhost", "=", "host", ";", "}", "public", "int", "getPort", "(", ")", "{", "return", "networkport", ";", "}", "public", "void", "setPort", "(", "int", "port", ")", "{", "this", ".", "networkport", "=", "port", ";", "}", "public", "String", "getUsername", "(", ")", "{", "return", "username", ";", "}", "public", "void", "setUsername", "(", "String", "username", ")", "{", "this", ".", "username", "=", "username", ";", "}", "public", "String", "getPassword", "(", ")", "{", "return", "username", ";", "}", "public", "void", "setPassword", "(", "String", "password", ")", "{", "this", ".", "password", "=", "password", ";", "}", "public", "void", "sendAuthentication", "(", "String", "username", ",", "String", "password", ")", "throws", "IOException", "{", "try", "{", "Document", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "newDocument", "(", ")", ";", "Element", "root", "=", "doc", ".", "createElement", "(", "\"message\"", ")", ";", "root", ".", "setAttribute", "(", "\"type\"", ",", "\"auth-request\"", ")", ";", "doc", ".", "appendChild", "(", "root", ")", ";", "Element", "auth", "=", "doc", ".", "createElement", "(", "\"\"", ")", ";", "auth", ".", "setAttribute", "(", "\"username\"", ",", "username", ")", ";", "auth", ".", "setAttribute", "(", "\"password\"", ",", "password", ")", ";", "root", ".", "appendChild", "(", "auth", ")", ";", "this", ".", "sendDocument", "(", "doc", ")", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "public", "boolean", "receiveAuthenticationResult", "(", ")", "throws", "IOException", "{", "try", "{", "Document", "doc", "=", "receiveDocument", "(", ")", ";", "Element", "root", "=", "doc", ".", "getDocumentElement", "(", ")", ";", "if", "(", "root", "==", "null", ")", "return", "false", ";", "if", "(", "!", "root", ".", "getAttribute", "(", "\"type\"", ")", ".", "equalsIgnoreCase", "(", "\"\"", ")", ")", "return", "false", ";", "NodeList", "nl", "=", "root", ".", "getChildNodes", "(", ")", ";", "Element", "authresult", "=", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "n", "=", "nl", ".", "item", "(", "i", ")", ";", "if", "(", "n", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "n", ".", "getNodeName", "(", ")", ".", "equalsIgnoreCase", "(", "\"\"", ")", ")", "{", "authresult", "=", "(", "Element", ")", "n", ";", "break", ";", "}", "}", "return", "authresult", ".", "getAttribute", "(", "\"result\"", ")", ".", "equalsIgnoreCase", "(", "\"ok\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "false", ";", "}", "public", "boolean", "doAuthentication", "(", "String", "username", ",", "String", "password", ")", "throws", "IOException", "{", "sendAuthentication", "(", "username", ",", "password", ")", ";", "return", "receiveAuthenticationResult", "(", ")", ";", "}", "public", "byte", "[", "]", "receivePacket", "(", ")", "throws", "IOException", ",", "SocketClosedException", "{", "ByteArrayOutputStream", "buffer", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "int", "read", "=", "inputstream", ".", "read", "(", ")", ";", "while", "(", "read", "!=", "0", ")", "{", "if", "(", "read", "==", "-", "1", ")", "{", "throw", "new", "SocketClosedException", "(", ")", ";", "}", "buffer", ".", "write", "(", "read", ")", ";", "read", "=", "inputstream", ".", "read", "(", ")", ";", "}", "return", "buffer", ".", "toByteArray", "(", ")", ";", "}", "public", "Document", "receiveDocument", "(", ")", "throws", "SAXException", "{", "try", "{", "byte", "[", "]", "raw", "=", "receivePacket", "(", ")", ";", "Document", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "parse", "(", "new", "ByteArrayInputStream", "(", "raw", ")", ")", ";", "return", "doc", ";", "}", "catch", "(", "SocketClosedException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ")", ";", "connected", "=", "false", ";", "}", "catch", "(", "SocketException", "e", ")", "{", "connected", "=", "false", ";", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "return", "null", ";", "}", "protected", "boolean", "connect", "(", ")", "{", "connected", "=", "false", ";", "try", "{", "socket", "=", "new", "Socket", "(", "networkhost", ",", "networkport", ")", ";", "inputstream", "=", "socket", ".", "getInputStream", "(", ")", ";", "outputstream", "=", "socket", ".", "getOutputStream", "(", ")", ";", "if", "(", "doAuthentication", "(", "username", ",", "password", ")", ")", "{", "processLogIn", "(", ")", ";", "connected", "=", "true", ";", "}", "else", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ")", ";", "}", "return", "connected", ";", "}", "public", "boolean", "isConnected", "(", ")", "{", "return", "connected", ";", "}", "public", "boolean", "processMessage", "(", "Element", "el_message", ")", "{", "String", "type", "=", "el_message", ".", "getAttribute", "(", "\"type\"", ")", ";", "if", "(", "type", ".", "equals", "(", "\"\"", ")", "||", "type", ".", "equals", "(", "\"sim-start\"", ")", "||", "type", ".", "equals", "(", "\"sim-end\"", ")", ")", "{", "long", "deadline", "=", "0", ";", "long", "currenttime", "=", "0", ";", "try", "{", "currenttime", "=", "Long", ".", "parseLong", "(", "el_message", ".", "getAttribute", "(", "\"timestamp\"", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "return", "true", ";", "}", "Element", "el_perception", "=", "null", ";", "NodeList", "nl", "=", "el_message", ".", "getChildNodes", "(", ")", ";", "String", "infoelementname", "=", "\"perception\"", ";", "if", "(", "type", ".", "equals", "(", "\"\"", ")", ")", "{", "infoelementname", "=", "\"perception\"", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-start\"", ")", ")", "{", "infoelementname", "=", "\"simulation\"", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-end\"", ")", ")", "{", "infoelementname", "=", "\"sim-result\"", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "n", "=", "nl", ".", "item", "(", "i", ")", ";", "if", "(", "n", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "n", ".", "getNodeName", "(", ")", ".", "equalsIgnoreCase", "(", "infoelementname", ")", ")", "{", "if", "(", "el_perception", "==", "null", ")", "{", "el_perception", "=", "(", "Element", ")", "n", ";", "break", ";", "}", "}", "}", "if", "(", "type", ".", "equals", "(", "\"\"", ")", ")", "{", "try", "{", "deadline", "=", "Long", ".", "parseLong", "(", "el_perception", ".", "getAttribute", "(", "\"deadline\"", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "return", "true", ";", "}", "processRequestAction", "(", "el_perception", ",", "currenttime", ",", "deadline", ")", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-start\"", ")", ")", "{", "processSimulationStart", "(", "el_perception", ",", "currenttime", ")", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-end\"", ")", ")", "{", "processSimulationEnd", "(", "el_perception", ",", "currenttime", ")", ";", "}", "}", "else", "if", "(", "type", ".", "equals", "(", "\"pong\"", ")", ")", "{", "NodeList", "nl", "=", "el_message", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "n", "=", "nl", ".", "item", "(", "i", ")", ";", "if", "(", "n", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "n", ".", "getNodeName", "(", ")", ".", "equalsIgnoreCase", "(", "\"payload\"", ")", ")", "{", "processPong", "(", "(", "(", "Element", ")", "n", ")", ".", "getAttribute", "(", "\"value\"", ")", ")", ";", "return", "true", ";", "}", "}", "}", "return", "true", ";", "}", "public", "abstract", "void", "processSimulationStart", "(", "Element", "perception", ",", "long", "currenttime", ")", ";", "public", "abstract", "void", "processRequestAction", "(", "Element", "perception", ",", "long", "currenttime", ",", "long", "deadline", ")", ";", "public", "abstract", "void", "processSimulationEnd", "(", "Element", "result", ",", "long", "currenttime", ")", ";", "public", "void", "processPong", "(", "String", "pong", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "pong", "+", "\"\"", ")", ";", "}", "public", "void", "processLogIn", "(", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "Object", "syncSend", "=", "new", "Object", "(", ")", ";", "public", "void", "sendDocument", "(", "Document", "doc", ")", "{", "try", "{", "if", "(", "logger", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "ByteArrayOutputStream", "temp", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "transformerfactory", ".", "newTransformer", "(", ")", ".", "transform", "(", "new", "DOMSource", "(", "doc", ")", ",", "new", "StreamResult", "(", "temp", ")", ")", ";", "logger", ".", "fine", "(", "\"Sending:\"", "+", "temp", ".", "toString", "(", ")", ")", ";", "}", "synchronized", "(", "syncSend", ")", "{", "transformerfactory", ".", "newTransformer", "(", ")", ".", "transform", "(", "new", "DOMSource", "(", "doc", ")", ",", "new", "StreamResult", "(", "outputstream", ")", ")", ";", "outputstream", ".", "write", "(", "0", ")", ";", "outputstream", ".", "flush", "(", ")", ";", "}", "}", "catch", "(", "TransformerConfigurationException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "catch", "(", "TransformerException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "connect", "(", ")", ";", "}", "}", "public", "void", "sendPing", "(", "String", "ping", ")", "throws", "IOException", "{", "Document", "doc", "=", "null", ";", "try", "{", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "newDocument", "(", ")", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "return", ";", "}", "try", "{", "Element", "root", "=", "doc", ".", "createElement", "(", "\"message\"", ")", ";", "doc", ".", "appendChild", "(", "root", ")", ";", "root", ".", "setAttribute", "(", "\"type\"", ",", "\"ping\"", ")", ";", "Element", "payload", "=", "doc", ".", "createElement", "(", "\"payload\"", ")", ";", "payload", ".", "setAttribute", "(", "\"value\"", ",", "ping", ")", ";", "root", ".", "appendChild", "(", "payload", ")", ";", "sendDocument", "(", "doc", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ")", ";", "}", "}", "}", "</s>" ]
9,108
[ "<s>", "package", "arch", ";", "import", "jason", ".", "JasonException", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "mas2j", ".", "ClassParameters", ";", "import", "jason", ".", "runtime", ".", "Settings", ";", "import", "java", ".", "util", ".", "List", ";", "import", "jmoise", ".", "OrgAgent", ";", "public", "class", "IdentifyCrashed", "extends", "OrgAgent", "{", "private", "boolean", "didPercept", "=", "true", ";", "private", "int", "maxCycleTime", "=", "4000", ";", "private", "boolean", "dead", "=", "false", ";", "private", "Thread", "agThread", "=", "null", ";", "private", "Thread", "checkThread", "=", "null", ";", "@", "Override", "public", "void", "initAg", "(", "String", "agClass", ",", "ClassParameters", "bbPars", ",", "String", "asSrc", ",", "Settings", "stts", ")", "throws", "JasonException", "{", "super", ".", "initAg", "(", "agClass", ",", "bbPars", ",", "asSrc", ",", "stts", ")", ";", "processParameters", "(", ")", ";", "createCheckThread", "(", ")", ";", "}", "void", "processParameters", "(", ")", "{", "String", "arg", "=", "getTS", "(", ")", ".", "getSettings", "(", ")", ".", "getUserParameter", "(", "\"maxCycleTime\"", ")", ";", "if", "(", "arg", "!=", "null", ")", "maxCycleTime", "=", "Integer", ".", "parseInt", "(", "arg", ")", ";", "}", "void", "createCheckThread", "(", ")", "{", "checkThread", "=", "new", "TestDead", "(", ")", ";", "checkThread", ".", "start", "(", ")", ";", "}", "@", "Override", "public", "List", "<", "Literal", ">", "perceive", "(", ")", "{", "agThread", "=", "Thread", ".", "currentThread", "(", ")", ";", "agDidPerceive", "(", ")", ";", "return", "super", ".", "perceive", "(", ")", ";", "}", "public", "synchronized", "void", "agDidPerceive", "(", ")", "{", "didPercept", "=", "true", ";", "notifyAll", "(", ")", ";", "}", "private", "synchronized", "void", "waitPerceive", "(", ")", "throws", "InterruptedException", "{", "wait", "(", "maxCycleTime", ")", ";", "}", "public", "boolean", "isCrashed", "(", ")", "{", "return", "!", "didPercept", ";", "}", "@", "Override", "public", "void", "stopAg", "(", ")", "{", "checkThread", ".", "interrupt", "(", ")", ";", "super", ".", "stopAg", "(", ")", ";", "}", "protected", "boolean", "fix1", "(", ")", "throws", "Exception", "{", "getTS", "(", ")", ".", "getLogger", "(", ")", ".", "warning", "(", "\"\"", ")", ";", "dead", "=", "true", ";", "waitPerceive", "(", ")", ";", "try", "{", "if", "(", "isCrashed", "(", ")", ")", "{", "return", "fix2", "(", ")", ";", "}", "else", "{", "getTS", "(", ")", ".", "getLogger", "(", ")", ".", "warning", "(", "\"\"", ")", ";", "return", "true", ";", "}", "}", "finally", "{", "dead", "=", "false", ";", "}", "}", "protected", "boolean", "fix2", "(", ")", "throws", "Exception", "{", "if", "(", "agThread", "!=", "null", ")", "{", "getTS", "(", ")", ".", "getLogger", "(", ")", ".", "warning", "(", "\"\"", ")", ";", "agThread", ".", "interrupt", "(", ")", ";", "waitPerceive", "(", ")", ";", "if", "(", "isCrashed", "(", ")", ")", "{", "getTS", "(", ")", ".", "getLogger", "(", ")", ".", "warning", "(", "\"\"", ")", ";", "return", "fix3", "(", ")", ";", "}", "else", "{", "getTS", "(", ")", ".", "getLogger", "(", ")", ".", "warning", "(", "\"\"", ")", ";", "return", "true", ";", "}", "}", "else", "{", "getTS", "(", ")", ".", "getLogger", "(", ")", ".", "warning", "(", "\"\"", ")", ";", "return", "fix3", "(", ")", ";", "}", "}", "protected", "boolean", "fix3", "(", ")", "throws", "Exception", "{", "return", "false", ";", "}", "@", "Override", "public", "boolean", "isRunning", "(", ")", "{", "return", "!", "dead", "&&", "super", ".", "isRunning", "(", ")", ";", "}", "class", "TestDead", "extends", "Thread", "{", "public", "TestDead", "(", ")", "{", "super", "(", "\"TestDeadAg-\"", "+", "getAgName", "(", ")", ")", ";", "}", "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "sleep", "(", "maxCycleTime", "*", "2", ")", ";", "while", "(", "IdentifyCrashed", ".", "super", ".", "isRunning", "(", ")", ")", "{", "didPercept", "=", "false", ";", "sleep", "(", "maxCycleTime", ")", ";", "if", "(", "isCrashed", "(", ")", ")", "{", "fix1", "(", ")", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}", "}", "</s>" ]
9,109
[ "<s>", "package", "arch", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "jason", ".", "util", ".", "asl2xml", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "FileWriter", ";", "import", "java", ".", "io", ".", "PrintWriter", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "LinkedList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "WriteStatusThread", "extends", "Thread", "{", "protected", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "WriteStatusThread", ".", "class", ".", "getName", "(", ")", ")", ";", "static", "WriteStatusThread", "instance", "=", "null", ";", "private", "WriteStatusThread", "(", ")", "{", "}", "public", "static", "WriteStatusThread", "create", "(", "CowboyArch", "owner", ",", "boolean", "writeLocations", ",", "boolean", "dumpAgsMind", ")", "{", "if", "(", "instance", "==", "null", ")", "{", "instance", "=", "new", "WriteStatusThread", "(", ")", ";", "instance", ".", "owner", "=", "owner", ";", "instance", ".", "writeLocations", "=", "writeLocations", ";", "instance", ".", "dumpAgsMinds", "=", "dumpAgsMind", ";", "instance", ".", "start", "(", ")", ";", "}", "return", "instance", ";", "}", "public", "static", "boolean", "isCreated", "(", ")", "{", "return", "instance", "!=", "null", ";", "}", "private", "CowboyArch", "owner", "=", "null", ";", "private", "boolean", "writeLocations", "=", "true", ";", "private", "boolean", "dumpAgsMinds", "=", "true", ";", "private", "Map", "<", "Integer", ",", "List", "<", "Location", ">", ">", "locations", ";", "private", "asl2xml", "transformer", "=", "new", "asl2xml", "(", ")", ";", "private", "static", "CowboyArch", "[", "]", "agents", "=", "new", "CowboyArch", "[", "WorldModel", ".", "agsByTeam", "]", ";", "public", "static", "void", "registerAgent", "(", "String", "name", ",", "CowboyArch", "arch", ")", "{", "agents", "[", "arch", ".", "getMyId", "(", ")", "]", "=", "arch", ";", "}", "public", "void", "reset", "(", ")", "{", "locations", "=", "new", "HashMap", "<", "Integer", ",", "List", "<", "Location", ">", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "WorldModel", ".", "agsByTeam", ";", "i", "++", ")", "{", "locations", ".", "put", "(", "i", ",", "new", "LinkedList", "<", "Location", ">", "(", ")", ")", ";", "}", "}", "public", "void", "run", "(", ")", "{", "String", "fileName", "=", "\"\"", ";", "PrintWriter", "out", "=", "null", ";", "try", "{", "out", "=", "new", "PrintWriter", "(", "fileName", ")", ";", "while", "(", "true", ")", "{", "try", "{", "if", "(", "writeLocations", ")", "writeLocations", "(", "out", ")", ";", "if", "(", "dumpAgsMinds", ")", "writeMind", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "return", ";", "}", "catch", "(", "Exception", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "sleep", "(", "1000", ")", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "out", ".", "close", "(", ")", ";", "}", "}", "private", "void", "writeMind", "(", ")", "{", "for", "(", "CowboyArch", "arch", ":", "agents", ")", "{", "if", "(", "arch", "==", "null", ")", "break", ";", "try", "{", "File", "dirmind", "=", "new", "File", "(", "\"mind-ag/\"", "+", "arch", ".", "getAgName", "(", ")", ")", ";", "if", "(", "!", "dirmind", ".", "exists", "(", ")", ")", "dirmind", ".", "mkdirs", "(", ")", ";", "String", "agmind", "=", "transformer", ".", "transform", "(", "arch", ".", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "getAgState", "(", ")", ")", ";", "String", "filename", "=", "String", ".", "format", "(", "\"%5d.xml\"", ",", "arch", ".", "getSimStep", "(", ")", ")", ".", "replaceAll", "(", "\"", "\"", ",", "\"0\"", ")", ";", "FileWriter", "outmind", "=", "new", "FileWriter", "(", "new", "File", "(", "dirmind", "+", "\"/\"", "+", "filename", ")", ")", ";", "outmind", ".", "write", "(", "agmind", ")", ";", "outmind", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "e", ")", ";", "}", "}", "}", "private", "void", "writeLocations", "(", "PrintWriter", "out", ")", "throws", "InterruptedException", "{", "long", "timebefore", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "waitNextCycle", "(", ")", ";", "long", "cycletime", "=", "System", ".", "currentTimeMillis", "(", ")", "-", "timebefore", ";", "StringBuilder", "s", "=", "new", "StringBuilder", "(", "String", ".", "format", "(", "\"Step", "%5d:\"", ",", "owner", ".", "getSimStep", "(", ")", "-", "1", ")", ")", ";", "for", "(", "int", "agId", "=", "0", ";", "agId", "<", "WorldModel", ".", "agsByTeam", ";", "agId", "++", ")", "{", "if", "(", "agents", "[", "agId", "]", "!=", "null", ")", "{", "Location", "agp", "=", "agents", "[", "agId", "]", ".", "getLastLocation", "(", ")", ";", "if", "(", "agp", "!=", "null", ")", "{", "int", "c", "=", "0", ";", "Iterator", "<", "Location", ">", "il", "=", "locations", ".", "get", "(", "agId", ")", ".", "iterator", "(", ")", ";", "while", "(", "il", ".", "hasNext", "(", ")", "&&", "il", ".", "next", "(", ")", ".", "equals", "(", "agp", ")", "&&", "c", "<=", "11", ")", "{", "c", "++", ";", "}", "String", "sc", "=", "\"*\"", ";", "if", "(", "c", "<", "10", ")", "sc", "=", "\"\"", "+", "c", ";", "locations", ".", "get", "(", "agId", ")", ".", "add", "(", "0", ",", "agp", ")", ";", "String", "lastAct", "=", "shortActionFormat", "(", "agents", "[", "agId", "]", ".", "getLastAction", "(", ")", ")", ";", "s", ".", "append", "(", "String", ".", "format", "(", "\"\"", ",", "agp", ".", "x", ",", "agp", ".", "y", ",", "sc", ",", "lastAct", ")", ")", ";", "}", "}", "}", "s", ".", "append", "(", "String", ".", "format", "(", "\"%6d", "ms\"", ",", "cycletime", ")", ")", ";", "logger", ".", "info", "(", "s", ".", "toString", "(", ")", ")", ";", "out", ".", "println", "(", "s", ".", "toString", "(", ")", ")", ";", "out", ".", "flush", "(", ")", ";", "}", "public", "String", "shortActionFormat", "(", "String", "act", ")", "{", "if", "(", "act", "==", "null", ")", "return", "\"?", "\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "east", ".", "toString", "(", ")", ")", ")", "return", "\"e", "\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "northeast", ".", "toString", "(", ")", ")", ")", "return", "\"ne\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "southeast", ".", "toString", "(", ")", ")", ")", "return", "\"se\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "west", ".", "toString", "(", ")", ")", ")", "return", "\"w", "\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "northwest", ".", "toString", "(", ")", ")", ")", "return", "\"nw\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "southwest", ".", "toString", "(", ")", ")", ")", "return", "\"sw\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "north", ".", "toString", "(", ")", ")", ")", "return", "\"n", "\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "south", ".", "toString", "(", ")", ")", ")", "return", "\"s", "\"", ";", "if", "(", "act", ".", "equals", "(", "WorldModel", ".", "Move", ".", "skip", ".", "toString", "(", ")", ")", ")", "return", "\"sk\"", ";", "return", "\"!!\"", ";", "}", "synchronized", "private", "void", "waitNextCycle", "(", ")", "throws", "InterruptedException", "{", "wait", "(", "10000", ")", ";", "}", "synchronized", "void", "go", "(", ")", "{", "notifyAll", "(", ")", ";", "}", "}", "</s>" ]
9,110
[ "<s>", "package", "arch", ";", "import", "jason", ".", "JasonException", ";", "import", "jason", ".", "RevisionFailedException", ";", "import", "jason", ".", "asSemantics", ".", "ActionExec", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "mas2j", ".", "ClassParameters", ";", "import", "jason", ".", "runtime", ".", "Settings", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Queue", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ConcurrentLinkedQueue", ";", "import", "java", ".", "util", ".", "concurrent", ".", "TimeUnit", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "Condition", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "Lock", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "public", "class", "ACArchitecture", "extends", "CowboyArch", "{", "public", "static", "final", "int", "actionTimeout", "=", "2000", ";", "private", "Logger", "logger", ";", "private", "ACProxy", "proxy", ";", "private", "List", "<", "Literal", ">", "percepts", "=", "new", "ArrayList", "<", "Literal", ">", "(", ")", ";", "private", "WaitSleep", "waitSleepThread", ";", "@", "Override", "public", "void", "initAg", "(", "String", "agClass", ",", "ClassParameters", "bbPars", ",", "String", "asSrc", ",", "Settings", "stts", ")", "throws", "JasonException", "{", "super", ".", "initAg", "(", "agClass", ",", "bbPars", ",", "asSrc", ",", "stts", ")", ";", "logger", "=", "Logger", ".", "getLogger", "(", "ACArchitecture", ".", "class", ".", "getName", "(", ")", "+", "\".\"", "+", "getAgName", "(", ")", ")", ";", "String", "username", "=", "stts", ".", "getUserParameter", "(", "\"username\"", ")", ";", "if", "(", "username", ".", "startsWith", "(", "\"\\\"\"", ")", ")", "username", "=", "username", ".", "substring", "(", "1", ",", "username", ".", "length", "(", ")", "-", "1", ")", ";", "username", "=", "username", ".", "replaceAll", "(", "\"#nid\"", ",", "\"\"", "+", "(", "getAgId", "(", "getAgName", "(", ")", ")", "+", "1", ")", ")", ";", "String", "password", "=", "stts", ".", "getUserParameter", "(", "\"password\"", ")", ";", "if", "(", "password", ".", "startsWith", "(", "\"\\\"\"", ")", ")", "password", "=", "password", ".", "substring", "(", "1", ",", "password", ".", "length", "(", ")", "-", "1", ")", ";", "waitSleepThread", "=", "new", "WaitSleep", "(", ")", ";", "waitSleepThread", ".", "start", "(", ")", ";", "proxy", "=", "new", "ACProxy", "(", "this", ",", "stts", ".", "getUserParameter", "(", "\"host\"", ")", ",", "Integer", ".", "parseInt", "(", "stts", ".", "getUserParameter", "(", "\"port\"", ")", ")", ",", "username", ",", "password", ")", ";", "new", "Thread", "(", "proxy", ",", "\"AgentProxy\"", "+", "username", ")", ".", "start", "(", ")", ";", "}", "@", "Override", "public", "void", "stopAg", "(", ")", "{", "super", ".", "stopAg", "(", ")", ";", "proxy", ".", "finish", "(", ")", ";", "waitSleepThread", ".", "interrupt", "(", ")", ";", "}", "@", "Override", "public", "List", "<", "Literal", ">", "perceive", "(", ")", "{", "return", "new", "ArrayList", "<", "Literal", ">", "(", "percepts", ")", ";", "}", "@", "Override", "public", "void", "sleep", "(", ")", "{", "waitSleepThread", ".", "go", "(", ")", ";", "super", ".", "sleep", "(", ")", ";", "}", "public", "void", "startNextStep", "(", "int", "step", ",", "List", "<", "Literal", ">", "p", ")", "{", "percepts", "=", "p", ";", "clModel", ".", "setStepcl", "(", "step", ")", ";", "new", "Thread", "(", "(", "Runnable", ")", "clModel", ")", ".", "start", "(", ")", ";", "waitSleepThread", ".", "newCycle", "(", ")", ";", "getTS", "(", ")", ".", "getUserAgArch", "(", ")", ".", "getArchInfraTier", "(", ")", ".", "wake", "(", ")", ";", "setSimStep", "(", "step", ")", ";", "}", "@", "Override", "public", "void", "act", "(", "ActionExec", "act", ",", "List", "<", "ActionExec", ">", "feedback", ")", "{", "if", "(", "act", ".", "getActionTerm", "(", ")", ".", "getFunctor", "(", ")", ".", "equals", "(", "\"do\"", ")", ")", "{", "waitSleepThread", ".", "addAction", "(", "act", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"\"", "+", "act", "+", "\"\"", ")", ";", "}", "}", "@", "Override", "void", "simulationEndPerceived", "(", "String", "result", ")", "throws", "RevisionFailedException", "{", "percepts", "=", "new", "ArrayList", "<", "Literal", ">", "(", ")", ";", "super", ".", "simulationEndPerceived", "(", "result", ")", ";", "}", "class", "WaitSleep", "extends", "Thread", "{", "ActionExec", "lastAction", "=", "null", ";", "String", "lastActionInCurrentCycle", ";", "Queue", "<", "ActionExec", ">", "toExecute", "=", "new", "ConcurrentLinkedQueue", "<", "ActionExec", ">", "(", ")", ";", "Lock", "lock", "=", "new", "ReentrantLock", "(", ")", ";", "Condition", "cycle", "=", "lock", ".", "newCondition", "(", ")", ";", "long", "timestartcycle", "=", "0", ";", "long", "timeLastAction", "=", "0", ";", "int", "cycleCounter", "=", "0", ";", "StringBuilder", "notsent", ";", "WaitSleep", "(", ")", "{", "super", "(", "\"\"", "+", "getAgName", "(", ")", ")", ";", "}", "void", "addAction", "(", "ActionExec", "action", ")", "{", "if", "(", "action", "==", "null", ")", "return", ";", "logger", ".", "info", "(", "\"\"", "+", "action", ".", "getActionTerm", "(", ")", "+", "\"\"", ")", ";", "lock", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "lastAction", "!=", "null", ")", "toExecute", ".", "offer", "(", "lastAction", ")", ";", "lastAction", "=", "action", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "void", "newCycle", "(", ")", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "cycleCounter", "++", ";", "if", "(", "getSimStep", "(", ")", "==", "1", ")", "cycleCounter", "=", "1", ";", "notsent", "=", "new", "StringBuilder", "(", ")", ";", "if", "(", "toExecute", ".", "size", "(", ")", ">", "1", ")", "{", "notsent", ".", "append", "(", "\"\"", ")", ";", "}", "List", "<", "ActionExec", ">", "feedback", "=", "getTS", "(", ")", ".", "getC", "(", ")", ".", "getFeedbackActions", "(", ")", ";", "synchronized", "(", "feedback", ")", "{", "while", "(", "!", "toExecute", ".", "isEmpty", "(", ")", ")", "{", "ActionExec", "action", "=", "toExecute", ".", "poll", "(", ")", ";", "action", ".", "setResult", "(", "true", ")", ";", "feedback", ".", "add", "(", "action", ")", ";", "if", "(", "!", "toExecute", ".", "isEmpty", "(", ")", ")", "notsent", ".", "append", "(", "action", ".", "getActionTerm", "(", ")", "+", "\"", "\"", ")", ";", "}", "}", "String", "w", "=", "\"\"", ";", "if", "(", "lastActionInCurrentCycle", "==", "null", "&&", "cycleCounter", ">", "10", ")", "{", "w", "=", "\"***", "\"", ";", "}", "String", "timetoact", "=", "\".", "\"", ";", "if", "(", "lastActionInCurrentCycle", "!=", "null", "&&", "timestartcycle", ">", "0", ")", "{", "timetoact", "=", "\"", "(act", "in", "\"", "+", "(", "timeLastAction", "-", "timestartcycle", ")", "+", "\"", "ms)\"", ";", "}", "timestartcycle", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "logger", ".", "info", "(", "w", "+", "\"\"", "+", "lastActionInCurrentCycle", "+", "\"", "for", "cycle", "\"", "+", "getSimStep", "(", ")", "+", "timetoact", "+", "notsent", ")", ";", "setLastAct", "(", "lastActionInCurrentCycle", ")", ";", "lastActionInCurrentCycle", "=", "null", ";", "lastAction", "=", "null", ";", "go", "(", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "void", "go", "(", ")", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "cycle", ".", "signal", "(", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "boolean", "waitSleep", "(", ")", "throws", "InterruptedException", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "return", "!", "cycle", ".", "await", "(", "actionTimeout", ",", "TimeUnit", ".", "MILLISECONDS", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "public", "void", "run", "(", ")", "{", "while", "(", "true", ")", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "waitSleep", "(", ")", ";", "if", "(", "lastAction", "!=", "null", ")", "{", "lastActionInCurrentCycle", "=", "lastAction", ".", "getActionTerm", "(", ")", ".", "getTerm", "(", "0", ")", ".", "toString", "(", ")", ";", "proxy", ".", "sendAction", "(", "lastActionInCurrentCycle", ")", ";", "toExecute", ".", "offer", "(", "lastAction", ")", ";", "timeLastAction", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "lastAction", "=", "null", ";", "}", "}", "catch", "(", "InterruptedException", "e", ")", "{", "return", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "lastAction", "+", "\"\"", ",", "e", ")", ";", "toExecute", ".", "clear", "(", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "}", "}", "}", "</s>" ]
9,111
[ "<s>", "package", "arch", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createLiteral", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createNumber", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createStructure", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Random", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "java", ".", "util", ".", "concurrent", ".", "CyclicBarrier", ";", "import", "java", ".", "util", ".", "concurrent", ".", "TimeUnit", ";", "import", "java", ".", "io", ".", "FileWriter", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilder", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilderFactory", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Document", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Element", ";", "import", "org", ".", "w3c", ".", "dom", ".", "NodeList", ";", "import", "env", ".", "WorldModel", ";", "import", "env", ".", "Cow", ";", "public", "class", "ACProxy", "extends", "ACAgent", "implements", "Runnable", "{", "String", "rid", ";", "ACArchitecture", "arq", ";", "boolean", "running", "=", "true", ";", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "ACProxy", ".", "class", ".", "getName", "(", ")", ")", ";", "private", "DocumentBuilder", "documentbuilder", ";", "ConnectionMonitor", "monitor", "=", "new", "ConnectionMonitor", "(", ")", ";", "private", "long", "timeSt", ",", "timeEnd", ";", "public", "ACProxy", "(", "ACArchitecture", "arq", ",", "String", "host", ",", "int", "port", ",", "String", "username", ",", "String", "password", ")", "{", "logger", "=", "Logger", ".", "getLogger", "(", "ACProxy", ".", "class", ".", "getName", "(", ")", "+", "\".\"", "+", "arq", ".", "getAgName", "(", ")", ")", ";", "if", "(", "host", ".", "startsWith", "(", "\"\\\"\"", ")", ")", "{", "host", "=", "host", ".", "substring", "(", "1", ",", "host", ".", "length", "(", ")", "-", "1", ")", ";", "}", "setPort", "(", "port", ")", ";", "setHost", "(", "host", ")", ";", "setUsername", "(", "username", ")", ";", "setPassword", "(", "password", ")", ";", "this", ".", "arq", "=", "arq", ";", "try", "{", "documentbuilder", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ".", "newDocumentBuilder", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "connect", "(", ")", ";", "monitor", ".", "start", "(", ")", ";", "}", "public", "void", "finish", "(", ")", "{", "running", "=", "false", ";", "monitor", ".", "interrupt", "(", ")", ";", "}", "public", "void", "run", "(", ")", "{", "while", "(", "running", ")", "{", "try", "{", "if", "(", "isConnected", "(", ")", ")", "{", "Document", "doc", "=", "receiveDocument", "(", ")", ";", "if", "(", "doc", "!=", "null", ")", "{", "Element", "el_root", "=", "doc", ".", "getDocumentElement", "(", ")", ";", "if", "(", "el_root", "!=", "null", ")", "{", "if", "(", "el_root", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"message\"", ")", ")", "{", "processMessage", "(", "el_root", ")", ";", "}", "else", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ")", ";", "}", "}", "else", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ")", ";", "}", "}", "}", "else", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "try", "{", "Thread", ".", "sleep", "(", "2000", ")", ";", "}", "catch", "(", "InterruptedException", "e1", ")", "{", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "}", "public", "void", "processLogIn", "(", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "public", "void", "processSimulationStart", "(", "Element", "simulation", ",", "long", "currenttime", ")", "{", "try", "{", "arq", ".", "setSimId", "(", "simulation", ".", "getAttribute", "(", "\"id\"", ")", ")", ";", "int", "gsizex", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"gsizex\"", ")", ")", ";", "int", "gsizey", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"gsizey\"", ")", ")", ";", "arq", ".", "gsizePerceived", "(", "gsizex", ",", "gsizey", ",", "simulation", ".", "getAttribute", "(", "\"opponent\"", ")", ")", ";", "int", "corralx0", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"corralx0\"", ")", ")", ";", "int", "corralx1", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"corralx1\"", ")", ")", ";", "int", "corraly0", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"corraly0\"", ")", ")", ";", "int", "corraly1", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"corraly1\"", ")", ")", ";", "arq", ".", "corralPerceived", "(", "new", "Location", "(", "corralx0", ",", "corraly0", ")", ",", "new", "Location", "(", "corralx1", ",", "corraly1", ")", ")", ";", "int", "steps", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"steps\"", ")", ")", ";", "arq", ".", "stepsPerceived", "(", "steps", ")", ";", "int", "lineOfSight", "=", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"lineOfSight\"", ")", ")", ";", "arq", ".", "lineOfSightPerceived", "(", "lineOfSight", ")", ";", "logger", ".", "info", "(", "\"\"", ")", ";", "rid", "=", "simulation", ".", "getAttribute", "(", "\"id\"", ")", ";", "timeSt", "=", "currenttime", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "public", "void", "processSimulationEnd", "(", "Element", "result", ",", "long", "currenttime", ")", "{", "try", "{", "timeEnd", "=", "currenttime", ";", "String", "score", "=", "result", ".", "getAttribute", "(", "\"score\"", ")", "+", "\"-\"", "+", "result", ".", "getAttribute", "(", "\"result\"", ")", ";", "logger", ".", "info", "(", "\"\"", "+", "score", ")", ";", "if", "(", "arq", ".", "myId", "==", "1", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "score", ")", ";", "logger", ".", "info", "(", "\"\"", "+", "(", "timeEnd", "-", "timeSt", ")", "+", "\"\"", ")", ";", "logger", ".", "info", "(", "\"\"", "+", "(", "timeEnd", "-", "timeSt", ")", "/", "60000.0", "+", "\"", "minutes\"", ")", ";", "String", "fileName", "=", "\"\"", ";", "FileWriter", "fw", "=", "new", "FileWriter", "(", "fileName", ",", "true", ")", ";", "fw", ".", "write", "(", "\"\"", ")", ";", "fw", ".", "write", "(", "timeEnd", "+", "\"n\"", ")", ";", "fw", ".", "write", "(", "(", "timeEnd", "-", "timeSt", ")", "+", "\"\"", "+", "(", "timeEnd", "-", "timeSt", ")", "/", "60000.0", "+", "\"", "minutes)n\"", ")", ";", "fw", ".", "write", "(", "score", "+", "\"n\"", ")", ";", "fw", ".", "close", "(", ")", ";", "}", "arq", ".", "simulationEndPerceived", "(", "result", ".", "getAttribute", "(", "\"result\"", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "public", "void", "processRequestAction", "(", "Element", "perception", ",", "long", "currenttime", ",", "long", "deadline", ")", "{", "try", "{", "List", "<", "Literal", ">", "percepts", "=", "new", "ArrayList", "<", "Literal", ">", "(", ")", ";", "rid", "=", "perception", ".", "getAttribute", "(", "\"id\"", ")", ";", "int", "agx", "=", "Integer", ".", "parseInt", "(", "perception", ".", "getAttribute", "(", "\"posx\"", ")", ")", ";", "int", "agy", "=", "Integer", ".", "parseInt", "(", "perception", ".", "getAttribute", "(", "\"posy\"", ")", ")", ";", "int", "step", "=", "Integer", ".", "parseInt", "(", "perception", ".", "getAttribute", "(", "\"step\"", ")", ")", ";", "int", "score", "=", "Integer", ".", "parseInt", "(", "perception", ".", "getAttribute", "(", "\"score\"", ")", ")", ";", "arq", ".", "locationPerceived", "(", "agx", ",", "agy", ")", ";", "arq", ".", "setScore", "(", "score", ")", ";", "arq", ".", "getCowModel", "(", ")", ".", "freePos", "(", "agx", ",", "agy", ")", ";", "Literal", "lpos", "=", "createLiteral", "(", "\"pos\"", ",", "createNumber", "(", "agx", ")", ",", "createNumber", "(", "agy", ")", ",", "createNumber", "(", "step", ")", ")", ";", "percepts", ".", "add", "(", "lpos", ")", ";", "arq", ".", "initKnownCows", "(", ")", ";", "List", "<", "Location", ">", "switches", "=", "new", "ArrayList", "<", "Location", ">", "(", ")", ";", "NodeList", "nl", "=", "perception", ".", "getElementsByTagName", "(", "\"cell\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Element", "cell", "=", "(", "Element", ")", "nl", ".", "item", "(", "i", ")", ";", "int", "cellx", "=", "Integer", ".", "parseInt", "(", "cell", ".", "getAttribute", "(", "\"x\"", ")", ")", ";", "int", "celly", "=", "Integer", ".", "parseInt", "(", "cell", ".", "getAttribute", "(", "\"y\"", ")", ")", ";", "int", "absx", "=", "agx", "+", "cellx", ";", "int", "absy", "=", "agy", "+", "celly", ";", "int", "unk", "=", "1", ";", "NodeList", "cnl", "=", "cell", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "cnl", ".", "getLength", "(", ")", ";", "j", "++", ")", "{", "if", "(", "cnl", ".", "item", "(", "j", ")", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "cellx", "!=", "0", "&&", "celly", "!=", "0", ")", "{", "Element", "type", "=", "(", "Element", ")", "cnl", ".", "item", "(", "j", ")", ";", "if", "(", "unk", "==", "1", "&&", "!", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"unknown\"", ")", ")", "{", "arq", ".", "getCowModel", "(", ")", ".", "freePos", "(", "absx", ",", "absy", ")", ";", "unk", "=", "0", ";", "}", "if", "(", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"agent\"", ")", ")", "{", "if", "(", "type", ".", "getAttribute", "(", "\"type\"", ")", ".", "equals", "(", "\"ally\"", ")", ")", "{", "}", "else", "if", "(", "type", ".", "getAttribute", "(", "\"type\"", ")", ".", "equals", "(", "\"enemy\"", ")", ")", "{", "arq", ".", "enemyPerceived", "(", "absx", ",", "absy", ")", ";", "}", "}", "else", "if", "(", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"cow\"", ")", ")", "{", "if", "(", "absx", "<", "arq", ".", "getModel", "(", ")", ".", "getWidth", "(", ")", "-", "1", "&&", "absx", "!=", "0", "&&", "absy", "!=", "00", "&&", "absy", "<", "arq", ".", "getModel", "(", ")", ".", "getHeight", "(", ")", "-", "1", ")", "{", "int", "cowId", "=", "Integer", ".", "parseInt", "(", "type", ".", "getAttribute", "(", "\"ID\"", ")", ")", ";", "arq", ".", "cowPerceived", "(", "cowId", ",", "absx", ",", "absy", ")", ";", "}", "}", "else", "if", "(", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"obstacle\"", ")", ")", "{", "arq", ".", "obstaclePerceived", "(", "absx", ",", "absy", ")", ";", "}", "else", "if", "(", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"corral\"", ")", "&&", "type", ".", "getAttribute", "(", "\"type\"", ")", ".", "equals", "(", "\"enemy\"", ")", ")", "{", "arq", ".", "enemyCorralPerceived", "(", "absx", ",", "absy", ")", ";", "}", "else", "if", "(", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"fence\"", ")", ")", "{", "boolean", "open", "=", "type", ".", "getAttribute", "(", "\"open\"", ")", ".", "equals", "(", "\"true\"", ")", ";", "arq", ".", "fencePerceived", "(", "absx", ",", "absy", ",", "open", ")", ";", "}", "else", "if", "(", "type", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"switch\"", ")", ")", "{", "switches", ".", "add", "(", "new", "Location", "(", "absx", ",", "absy", ")", ")", ";", "}", "}", "}", "}", "arq", ".", "getCowModel", "(", ")", ".", "updateCows", "(", ")", ";", "for", "(", "Location", "l", ":", "switches", ")", "{", "arq", ".", "switchPerceived", "(", "l", ".", "x", ",", "l", ".", "y", ")", ";", "}", "Cow", "[", "]", "cows", "=", "arq", ".", "getCowModel", "(", ")", ".", "getCows", "(", ")", ";", "for", "(", "Cow", "cCow", ":", "cows", ")", "{", "Literal", "lc", "=", "createLiteral", "(", "\"cow\"", ",", "createNumber", "(", "cCow", ".", "id", ")", ",", "createNumber", "(", "cCow", ".", "x", ")", ",", "createNumber", "(", "cCow", ".", "y", ")", ")", ";", "lc", ".", "addAnnot", "(", "createStructure", "(", "\"step\"", ",", "createNumber", "(", "cCow", ".", "step", ")", ")", ")", ";", "percepts", ".", "add", "(", "lc", ")", ";", "}", "arq", ".", "startNextStep", "(", "step", ",", "percepts", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "public", "void", "sendAction", "(", "String", "action", ")", "{", "try", "{", "logger", ".", "info", "(", "\"\"", "+", "action", "+", "\"", "for", "rid", "\"", "+", "rid", "+", "\"", "at", "\"", "+", "arq", ".", "model", ".", "getAgPos", "(", "arq", ".", "getMyId", "(", ")", ")", ")", ";", "Document", "doc", "=", "documentbuilder", ".", "newDocument", "(", ")", ";", "Element", "el_response", "=", "doc", ".", "createElement", "(", "\"message\"", ")", ";", "el_response", ".", "setAttribute", "(", "\"type\"", ",", "\"action\"", ")", ";", "doc", ".", "appendChild", "(", "el_response", ")", ";", "Element", "el_action", "=", "doc", ".", "createElement", "(", "\"action\"", ")", ";", "if", "(", "action", "!=", "null", ")", "{", "el_action", ".", "setAttribute", "(", "\"type\"", ",", "action", ")", ";", "}", "el_action", ".", "setAttribute", "(", "\"id\"", ",", "rid", ")", ";", "el_response", ".", "appendChild", "(", "el_action", ")", ";", "sendDocument", "(", "doc", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "}", "@", "Override", "public", "void", "processPong", "(", "String", "pong", ")", "{", "monitor", ".", "processPong", "(", "pong", ")", ";", "}", "class", "ConnectionMonitor", "extends", "Thread", "{", "long", "sentTime", "=", "0", ";", "int", "count", "=", "0", ";", "boolean", "ok", "=", "true", ";", "String", "pingMsg", ";", "synchronized", "public", "void", "run", "(", ")", "{", "int", "d", "=", "new", "Random", "(", ")", ".", "nextInt", "(", "15000", ")", ";", "try", "{", "while", "(", "running", ")", "{", "if", "(", "isConnected", "(", ")", ")", "sleep", "(", "40000", "+", "d", ")", ";", "else", "sleep", "(", "5000", ")", ";", "count", "++", ";", "sentTime", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "ok", "=", "false", ";", "if", "(", "isConnected", "(", ")", ")", "{", "pingMsg", "=", "\"test:\"", "+", "count", ";", "logger", ".", "info", "(", "\"\"", "+", "pingMsg", ")", ";", "sendPing", "(", "pingMsg", ")", ";", "waitPong", "(", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "if", "(", "!", "ok", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "connect", "(", ")", ";", "}", "}", "}", "catch", "(", "InterruptedException", "e", ")", "{", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "WARNING", ",", "\"\"", ",", "e", ")", ";", "}", "}", "synchronized", "void", "waitPong", "(", ")", "throws", "Exception", "{", "wait", "(", "10000", ")", ";", "}", "synchronized", "void", "processPong", "(", "String", "pong", ")", "{", "long", "time", "=", "System", ".", "currentTimeMillis", "(", ")", "-", "sentTime", ";", "logger", ".", "info", "(", "\"Pong", "\"", "+", "pong", "+", "\"", "for", "ping", "\"", "+", "pingMsg", "+", "\"", "in", "\"", "+", "time", "+", "\"", "milisec\"", ")", ";", "ok", "=", "true", ";", "notify", "(", ")", ";", "}", "}", "}", "</s>" ]
9,112
[ "<s>", "package", "arch", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createLiteral", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createNumber", ";", "import", "jason", ".", "architecture", ".", "AgArch", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "bb", ".", "BeliefBase", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "io", ".", "BufferedReader", ";", "import", "java", ".", "io", ".", "BufferedWriter", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "FileReader", ";", "import", "java", ".", "io", ".", "FileWriter", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Random", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "jia", ".", "Search", ";", "import", "jia", ".", "Vec", ";", "import", "moise", ".", "simple", ".", "oe", ".", "Pair", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "LocalWorldModel", "extends", "WorldModel", "{", "int", "[", "]", "[", "]", "visited", ";", "int", "minVisited", "=", "0", ";", "private", "Random", "random", "=", "new", "Random", "(", ")", ";", "Set", "<", "Vec", ">", "knownCows", "=", "new", "HashSet", "<", "Vec", ">", "(", ")", ";", "boolean", "isKnownCowsUptodate", "=", "false", ";", "int", "[", "]", "[", "]", "cowsrep", ";", "int", "[", "]", "[", "]", "obsrep", ";", "int", "[", "]", "[", "]", "enemycorralrep", ";", "Map", "<", "Pair", "<", "Location", ",", "Location", ">", ",", "Integer", ">", "dist", "=", "new", "HashMap", "<", "Pair", "<", "Location", ",", "Location", ">", ",", "Integer", ">", "(", ")", ";", "boolean", "distOutdated", "=", "true", ";", "BeliefBase", "bb", ";", "public", "LocalWorldModel", "(", "int", "w", ",", "int", "h", ",", "int", "nbAg", ",", "BeliefBase", "bb", ")", "{", "super", "(", "w", ",", "h", ",", "nbAg", ")", ";", "this", ".", "bb", "=", "bb", ";", "visited", "=", "new", "int", "[", "getWidth", "(", ")", "]", "[", "getHeight", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "visited", "[", "i", "]", "[", "j", "]", "=", "0", ";", "cowsrep", "=", "new", "int", "[", "getWidth", "(", ")", "]", "[", "getHeight", "(", ")", "]", ";", "obsrep", "=", "new", "int", "[", "getWidth", "(", ")", "]", "[", "getHeight", "(", ")", "]", ";", "enemycorralrep", "=", "new", "int", "[", "getWidth", "(", ")", "]", "[", "getHeight", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "{", "obsrep", "[", "i", "]", "[", "j", "]", "=", "0", ";", "enemycorralrep", "[", "i", "]", "[", "j", "]", "=", "0", ";", "}", "}", "@", "Override", "public", "void", "add", "(", "int", "value", ",", "int", "x", ",", "int", "y", ")", "{", "switch", "(", "value", ")", "{", "case", "OBSTACLE", ":", "increp", "(", "obsrep", ",", "x", ",", "y", ",", "1", ",", "1", ")", ";", "distOutdated", "=", "true", ";", "break", ";", "case", "ENEMYCORRAL", ":", "increp", "(", "enemycorralrep", ",", "x", ",", "y", ",", "1", ",", "2", ")", ";", "break", ";", "case", "OPEN_FENCE", ":", "if", "(", "hasObject", "(", "CLOSED_FENCE", ",", "x", ",", "y", ")", ")", "remove", "(", "CLOSED_FENCE", ",", "x", ",", "y", ")", ";", "break", ";", "case", "CLOSED_FENCE", ":", "if", "(", "hasObject", "(", "OPEN_FENCE", ",", "x", ",", "y", ")", ")", "remove", "(", "OPEN_FENCE", ",", "x", ",", "y", ")", ";", "break", ";", "case", "SWITCH", ":", "if", "(", "hasObject", "(", "FENCE", ",", "x", "+", "1", ",", "y", ")", ")", "add", "(", "OBSTACLE", ",", "x", "+", "1", ",", "y", ")", ";", "if", "(", "hasObject", "(", "FENCE", ",", "x", "-", "1", ",", "y", ")", ")", "add", "(", "OBSTACLE", ",", "x", "-", "1", ",", "y", ")", ";", "if", "(", "hasObject", "(", "FENCE", ",", "x", ",", "y", "+", "1", ")", ")", "add", "(", "OBSTACLE", ",", "x", ",", "y", "+", "1", ")", ";", "if", "(", "hasObject", "(", "FENCE", ",", "x", ",", "y", "-", "1", ")", ")", "add", "(", "OBSTACLE", ",", "x", ",", "y", "-", "1", ")", ";", "add", "(", "OBSTACLE", ",", "x", ",", "y", ")", ";", "break", ";", "}", "super", ".", "add", "(", "value", ",", "x", ",", "y", ")", ";", "}", "public", "boolean", "isHorizontalFence", "(", "int", "x", ",", "int", "y", ")", "{", "return", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "x", "+", "1", ",", "y", ")", "||", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "x", "-", "1", ",", "y", ")", ";", "}", "public", "void", "clearKnownCows", "(", ")", "{", "isKnownCowsUptodate", "=", "false", ";", "}", "public", "Set", "<", "Vec", ">", "getKnownCows", "(", ")", "{", "synchronized", "(", "knownCows", ")", "{", "if", "(", "!", "isKnownCowsUptodate", ")", "updateCowsFromBB", "(", ")", ";", "return", "new", "HashSet", "<", "Vec", ">", "(", "knownCows", ")", ";", "}", "}", "private", "static", "final", "Literal", "cowLiteral", "=", "Literal", ".", "parseLiteral", "(", "\"cow(Id,X,Y)\"", ")", ";", "private", "void", "updateCowsFromBB", "(", ")", "{", "if", "(", "bb", "==", "null", ")", "return", ";", "synchronized", "(", "knownCows", ")", "{", "removeAll", "(", "WorldModel", ".", "COW", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "cowsrep", "[", "i", "]", "[", "j", "]", "=", "0", ";", "knownCows", ".", "clear", "(", ")", ";", "Iterator", "<", "Literal", ">", "i", "=", "bb", ".", "getCandidateBeliefs", "(", "cowLiteral", ",", "null", ")", ";", "if", "(", "i", "!=", "null", ")", "{", "while", "(", "i", ".", "hasNext", "(", ")", ")", "{", "Literal", "c", "=", "i", ".", "next", "(", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "c", ".", "getTerm", "(", "1", ")", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "c", ".", "getTerm", "(", "2", ")", ")", ".", "solve", "(", ")", ";", "addKnownCow", "(", "x", ",", "y", ")", ";", "}", "}", "isKnownCowsUptodate", "=", "true", ";", "}", "}", "public", "void", "addKnownCow", "(", "int", "x", ",", "int", "y", ")", "{", "add", "(", "WorldModel", ".", "COW", ",", "x", ",", "y", ")", ";", "knownCows", ".", "add", "(", "new", "Vec", "(", "this", ",", "x", ",", "y", ")", ")", ";", "increp", "(", "cowsrep", ",", "x", ",", "y", ",", "2", ",", "1", ")", ";", "}", "public", "int", "getCowsRep", "(", "int", "x", ",", "int", "y", ")", "{", "return", "cowsrep", "[", "x", "]", "[", "y", "]", ";", "}", "public", "int", "getObsRep", "(", "int", "x", ",", "int", "y", ")", "{", "return", "obsrep", "[", "x", "]", "[", "y", "]", ";", "}", "public", "int", "getEnemyCorralRep", "(", "int", "x", ",", "int", "y", ")", "{", "return", "enemycorralrep", "[", "x", "]", "[", "y", "]", ";", "}", "private", "void", "increp", "(", "int", "[", "]", "[", "]", "m", ",", "int", "x", ",", "int", "y", ",", "int", "ratio", ",", "int", "value", ")", "{", "for", "(", "int", "r", "=", "1", ";", "r", "<=", "ratio", ";", "r", "++", ")", "for", "(", "int", "c", "=", "x", "-", "r", ";", "c", "<=", "x", "+", "r", ";", "c", "++", ")", "for", "(", "int", "l", "=", "y", "-", "r", ";", "l", "<=", "y", "+", "r", ";", "l", "++", ")", "if", "(", "inGrid", "(", "c", ",", "l", ")", ")", "{", "m", "[", "c", "]", "[", "l", "]", "+=", "value", ";", "}", "}", "public", "Location", "nearFree", "(", "Location", "l", ",", "List", "<", "Location", ">", "occupied", ")", "throws", "Exception", "{", "int", "w", "=", "0", ";", "Location", "newl", ";", "if", "(", "occupied", "==", "null", ")", "occupied", "=", "Collections", ".", "emptyList", "(", ")", ";", "while", "(", "true", ")", "{", "for", "(", "int", "y", "=", "l", ".", "y", "-", "w", "+", "1", ";", "y", "<", "l", ".", "y", "+", "w", ";", "y", "++", ")", "{", "newl", "=", "new", "Location", "(", "l", ".", "x", "-", "w", ",", "y", ")", ";", "if", "(", "isFree", "(", "newl", ")", "&&", "!", "occupied", ".", "contains", "(", "newl", ")", ")", "return", "newl", ";", "newl", "=", "new", "Location", "(", "l", ".", "x", "+", "w", ",", "y", ")", ";", "if", "(", "isFree", "(", "newl", ")", "&&", "!", "occupied", ".", "contains", "(", "newl", ")", ")", "return", "newl", ";", "}", "for", "(", "int", "x", "=", "l", ".", "x", "-", "w", ";", "x", "<=", "l", ".", "x", "+", "w", ";", "x", "++", ")", "{", "newl", "=", "new", "Location", "(", "x", ",", "l", ".", "y", "-", "w", ")", ";", "if", "(", "isFree", "(", "newl", ")", "&&", "!", "occupied", ".", "contains", "(", "newl", ")", ")", "return", "newl", ";", "newl", "=", "new", "Location", "(", "x", ",", "l", ".", "y", "+", "w", ")", ";", "if", "(", "isFree", "(", "newl", ")", "&&", "!", "occupied", ".", "contains", "(", "newl", ")", ")", "return", "newl", ";", "}", "w", "++", ";", "}", "}", "public", "Set", "<", "Location", ">", "getAllObj", "(", "int", "obj", ")", "{", "Set", "<", "Location", ">", "all", "=", "new", "HashSet", "<", "Location", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "if", "(", "hasObject", "(", "obj", ",", "i", ",", "j", ")", ")", "all", ".", "add", "(", "new", "Location", "(", "i", ",", "j", ")", ")", ";", "return", "all", ";", "}", "public", "int", "countObjInArea", "(", "int", "obj", ",", "Location", "startPoint", ",", "int", "size", ")", "{", "int", "c", "=", "0", ";", "for", "(", "int", "x", "=", "startPoint", ".", "x", "-", "size", ";", "x", "<=", "startPoint", ".", "x", "+", "size", ";", "x", "++", ")", "{", "for", "(", "int", "y", "=", "startPoint", ".", "y", "-", "size", ";", "y", "<=", "startPoint", ".", "y", "+", "size", ";", "y", "++", ")", "{", "if", "(", "hasObject", "(", "obj", ",", "x", ",", "y", ")", ")", "{", "c", "++", ";", "}", "}", "}", "return", "c", ";", "}", "public", "int", "getVisited", "(", "Location", "l", ")", "{", "return", "visited", "[", "l", ".", "x", "]", "[", "l", ".", "y", "]", ";", "}", "public", "void", "incVisited", "(", "Location", "l", ")", "{", "incVisited", "(", "l", ".", "x", ",", "l", ".", "y", ")", ";", "}", "public", "void", "incVisited", "(", "int", "x", ",", "int", "y", ")", "{", "visited", "[", "x", "]", "[", "y", "]", "+=", "2", ";", "increp", "(", "visited", ",", "x", ",", "y", ",", "4", ",", "1", ")", ";", "}", "public", "int", "pathLength", "(", "Location", "start", ",", "Location", "target", ",", "boolean", "fenceAsObstacle", ",", "AgArch", "arch", ")", "throws", "Exception", "{", "if", "(", "distOutdated", ")", "{", "synchronized", "(", "dist", ")", "{", "dist", ".", "clear", "(", ")", ";", "distOutdated", "=", "false", ";", "}", "}", "Pair", "<", "Location", ",", "Location", ">", "pair", "=", "new", "Pair", "<", "Location", ",", "Location", ">", "(", "start", ",", "target", ")", ";", "Integer", "iDistance", "=", "null", ";", "if", "(", "!", "fenceAsObstacle", ")", "{", "iDistance", "=", "dist", ".", "get", "(", "pair", ")", ";", "if", "(", "iDistance", "==", "null", ")", "{", "pair", "=", "new", "Pair", "<", "Location", ",", "Location", ">", "(", "target", ",", "start", ")", ";", "iDistance", "=", "dist", ".", "get", "(", "pair", ")", ";", "}", "if", "(", "iDistance", "!=", "null", ")", "{", "return", "iDistance", ";", "}", "}", "Nodo", "solution", "=", "new", "Search", "(", "this", ",", "start", ",", "target", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "fenceAsObstacle", ",", "arch", ")", ".", "search", "(", ")", ";", "if", "(", "solution", "==", "null", ")", "{", "return", "-", "1", ";", "}", "else", "{", "int", "distance", "=", "solution", ".", "getProfundidade", "(", ")", ";", "if", "(", "!", "fenceAsObstacle", ")", "{", "synchronized", "(", "dist", ")", "{", "dist", ".", "put", "(", "pair", ",", "distance", ")", ";", "}", "}", "return", "distance", ";", "}", "}", "public", "Location", "getNearLeastVisited", "(", "Location", "agloc", ",", "Location", "tl", ",", "Location", "br", ")", "throws", "Exception", "{", "if", "(", "!", "agloc", ".", "isInArea", "(", "tl", ",", "br", ")", ")", "{", "return", "nearFree", "(", "new", "Location", "(", "(", "tl", ".", "x", "+", "br", ".", "x", ")", "/", "2", ",", "(", "tl", ".", "y", "+", "br", ".", "y", ")", "/", "2", ")", ",", "null", ")", ";", "}", "Location", "better", "=", "null", ";", "int", "loopcount", "=", "0", ";", "while", "(", "loopcount", "<", "100", ")", "{", "loopcount", "++", ";", "int", "x", "=", "agloc", ".", "x", ";", "int", "y", "=", "agloc", ".", "y", ";", "int", "w", "=", "1", ";", "int", "dx", "=", "0", ";", "int", "dy", "=", "0", ";", "int", "stage", "=", "1", ";", "better", "=", "null", ";", "while", "(", "w", "<", "getWidth", "(", ")", ")", "{", "switch", "(", "stage", ")", "{", "case", "1", ":", "if", "(", "dx", "<", "w", ")", "{", "dx", "++", ";", "break", ";", "}", "else", "{", "stage", "=", "2", ";", "}", "case", "2", ":", "if", "(", "dy", "<", "w", ")", "{", "dy", "++", ";", "break", ";", "}", "else", "{", "stage", "=", "3", ";", "}", "case", "3", ":", "if", "(", "dx", ">", "0", ")", "{", "dx", "--", ";", "break", ";", "}", "else", "{", "stage", "=", "4", ";", "}", "case", "4", ":", "if", "(", "dy", ">", "0", ")", "{", "dy", "--", ";", "break", ";", "}", "else", "{", "stage", "=", "1", ";", "x", "--", ";", "y", "--", ";", "w", "+=", "2", ";", "}", "}", "Location", "l", "=", "new", "Location", "(", "x", "+", "dx", ",", "y", "+", "dy", ")", ";", "if", "(", "isFree", "(", "l", ")", "&&", "!", "l", ".", "equals", "(", "agloc", ")", "&&", "l", ".", "isInArea", "(", "tl", ",", "br", ")", "&&", "!", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "l", ".", "x", ",", "l", ".", "y", ")", ")", "{", "if", "(", "visited", "[", "l", ".", "x", "]", "[", "l", ".", "y", "]", "<", "minVisited", ")", "{", "return", "l", ";", "}", "if", "(", "visited", "[", "l", ".", "x", "]", "[", "l", ".", "y", "]", "==", "minVisited", ")", "{", "if", "(", "better", "==", "null", ")", "{", "better", "=", "l", ";", "}", "else", "if", "(", "l", ".", "distance", "(", "agloc", ")", "<", "better", ".", "distance", "(", "agloc", ")", ")", "{", "better", "=", "l", ";", "}", "else", "if", "(", "l", ".", "distance", "(", "agloc", ")", "==", "better", ".", "distance", "(", "agloc", ")", "&&", "random", ".", "nextBoolean", "(", ")", ")", "{", "better", "=", "l", ";", "}", "}", "}", "}", "if", "(", "better", "!=", "null", ")", "{", "return", "better", ";", "}", "minVisited", "++", ";", "}", "return", "better", ";", "}", "public", "void", "clearAgView", "(", "Location", "l", ")", "{", "clearAgView", "(", "l", ".", "x", ",", "l", ".", "y", ")", ";", "}", "private", "static", "final", "int", "cleanPerception", "=", "~", "(", "ENEMY", ")", ";", "public", "void", "clearAgView", "(", "int", "x", ",", "int", "y", ")", "{", "int", "r", "=", "agPerceptionRatio", ";", "for", "(", "int", "c", "=", "x", "-", "r", ";", "c", "<=", "x", "+", "r", ";", "c", "++", ")", "{", "for", "(", "int", "l", "=", "y", "-", "r", ";", "l", "<=", "y", "+", "r", ";", "l", "++", ")", "{", "if", "(", "inGrid", "(", "c", ",", "l", ")", ")", "{", "data", "[", "c", "]", "[", "l", "]", "&=", "cleanPerception", ";", "if", "(", "view", "!=", "null", ")", "view", ".", "update", "(", "c", ",", "l", ")", ";", "}", "}", "}", "}", "private", "static", "final", "File", "directory", "=", "new", "File", "(", "\"bak-obs\"", ")", ";", "public", "void", "createStoreObsThread", "(", "final", "CowboyArch", "arch", ")", "{", "new", "Thread", "(", "\"store", "obs\"", ")", "{", "@", "Override", "public", "void", "run", "(", ")", "{", "directory", ".", "mkdirs", "(", ")", ";", "while", "(", "true", ")", "{", "try", "{", "sleep", "(", "10000", "+", "random", ".", "nextInt", "(", "10000", ")", ")", ";", "StringBuilder", "sout", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "{", "if", "(", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "i", ",", "j", ")", "&&", "!", "arch", ".", "isEphemeralObstacle", "(", "new", "Location", "(", "i", ",", "j", ")", ")", ")", "sout", ".", "append", "(", "\"obstacle(\"", "+", "i", "+", "\",\"", "+", "j", "+", "\")n\"", ")", ";", "if", "(", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "i", ",", "j", ")", ")", "sout", ".", "append", "(", "\"fence(\"", "+", "i", "+", "\",\"", "+", "j", "+", "\")n\"", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "{", "if", "(", "hasObject", "(", "WorldModel", ".", "SWITCH", ",", "i", ",", "j", ")", ")", "sout", ".", "append", "(", "\"switch(\"", "+", "i", "+", "\",\"", "+", "j", "+", "\")n\"", ")", ";", "}", "BufferedWriter", "out", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "getObstaclesFileName", "(", "arch", ")", ")", ")", ";", "out", ".", "write", "(", "sout", ".", "toString", "(", ")", ")", ";", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "}", ".", "start", "(", ")", ";", "}", "public", "void", "restoreObstaclesFromFile", "(", "final", "CowboyArch", "arch", ")", "{", "File", "f", "=", "new", "File", "(", "getObstaclesFileName", "(", "arch", ")", ")", ";", "if", "(", "f", ".", "exists", "(", ")", ")", "{", "Set", "<", "Location", ">", "included", "=", "new", "HashSet", "<", "Location", ">", "(", ")", ";", "try", "{", "arch", ".", "logger", ".", "info", "(", "\"\"", "+", "f", ")", ";", "BufferedReader", "in", "=", "new", "BufferedReader", "(", "new", "FileReader", "(", "f", ")", ")", ";", "String", "lin", "=", "in", ".", "readLine", "(", ")", ";", "while", "(", "lin", "!=", "null", ")", "{", "Literal", "obs", "=", "ASSyntax", ".", "parseLiteral", "(", "lin", ")", ";", "Location", "l", "=", "new", "Location", "(", "(", "int", ")", "(", "(", "NumberTerm", ")", "obs", ".", "getTerm", "(", "0", ")", ")", ".", "solve", "(", ")", ",", "(", "int", ")", "(", "(", "NumberTerm", ")", "obs", ".", "getTerm", "(", "1", ")", ")", ".", "solve", "(", ")", ")", ";", "if", "(", "obs", ".", "getFunctor", "(", ")", ".", "equals", "(", "\"obstacle\"", ")", ")", "{", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", ";", "included", ".", "add", "(", "l", ")", ";", "}", "else", "if", "(", "obs", ".", "getFunctor", "(", ")", ".", "equals", "(", "\"fence\"", ")", ")", "{", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "l", ")", ";", "included", ".", "add", "(", "l", ")", ";", "}", "else", "if", "(", "obs", ".", "getFunctor", "(", ")", ".", "equals", "(", "\"switch\"", ")", ")", "{", "add", "(", "WorldModel", ".", "SWITCH", ",", "l", ")", ";", "arch", ".", "getTS", "(", ")", ".", "getAg", "(", ")", ".", "addBel", "(", "createLiteral", "(", "\"switch\"", ",", "createNumber", "(", "l", ".", "x", ")", ",", "createNumber", "(", "l", ".", "y", ")", ")", ")", ";", "included", ".", "add", "(", "l", ")", ";", "}", "lin", "=", "in", ".", "readLine", "(", ")", ";", "}", "}", "catch", "(", "ArrayIndexOutOfBoundsException", "e", ")", "{", "for", "(", "Location", "l", ":", "included", ")", "{", "remove", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", ";", "remove", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "l", ")", ";", "remove", "(", "WorldModel", ".", "SWITCH", ",", "l", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "@", "SuppressWarnings", "(", "\"deprecation\"", ")", "private", "String", "getObstaclesFileName", "(", "final", "CowboyArch", "arch", ")", "{", "return", "directory", "+", "\"/\"", "+", "arch", ".", "getAgName", "(", ")", "+", "\"-\"", "+", "getOpponent", "(", ")", "+", "arch", ".", "getSimId", "(", ")", "+", "getMaxSteps", "(", ")", "+", "getCorral", "(", ")", "+", "\"-\"", "+", "new", "Date", "(", ")", ".", "getDay", "(", ")", "+", "\".bb\"", ";", "}", "}", "</s>" ]
9,113
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "Atom", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "Random", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "direction", "extends", "DefaultInternalAction", "{", "WorldModel", ".", "Move", "[", "]", "actionsOrder", "=", "new", "WorldModel", ".", "Move", "[", "WorldModel", ".", "nbActions", "]", ";", "Random", "random", "=", "new", "Random", "(", ")", ";", "public", "direction", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "WorldModel", ".", "nbActions", ";", "i", "++", ")", "{", "actionsOrder", "[", "i", "]", "=", "Search", ".", "defaultActions", "[", "i", "]", ";", "}", "}", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "try", "{", "String", "sAction", "=", "\"skip\"", ";", "Nodo", "solution", "=", "findPath", "(", "ts", ",", "terms", ")", ";", "if", "(", "solution", "!=", "null", ")", "{", "WorldModel", ".", "Move", "m", "=", "Search", ".", "firstAction", "(", "solution", ")", ";", "if", "(", "m", "!=", "null", ")", "sAction", "=", "m", ".", "toString", "(", ")", ";", "}", "else", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "terms", "[", "0", "]", "+", "\",\"", "+", "terms", "[", "1", "]", "+", "\"", "to", "\"", "+", "terms", "[", "2", "]", "+", "\",\"", "+", "terms", "[", "3", "]", "+", "\"!\"", "+", "\"n\"", "+", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "terms", "[", "4", "]", ",", "new", "Atom", "(", "sAction", ")", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "protected", "Nodo", "findPath", "(", "TransitionSystem", "ts", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "Nodo", "solution", "=", "null", ";", "int", "iagx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "iagy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "int", "itox", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "int", "itoy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "3", "]", ")", ".", "solve", "(", ")", ";", "if", "(", "model", ".", "inGrid", "(", "itox", ",", "itoy", ")", ")", "{", "while", "(", "!", "model", ".", "isFreeOfObstacle", "(", "itox", ",", "itoy", ")", "&&", "itox", ">", "0", ")", "itox", "--", ";", "while", "(", "!", "model", ".", "isFreeOfObstacle", "(", "itox", ",", "itoy", ")", "&&", "itox", "<", "model", ".", "getWidth", "(", ")", ")", "itox", "++", ";", "Location", "from", "=", "new", "Location", "(", "iagx", ",", "iagy", ")", ";", "Location", "to", "=", "new", "Location", "(", "itox", ",", "itoy", ")", ";", "int", "i1", "=", "random", ".", "nextInt", "(", "WorldModel", ".", "nbActions", ")", ";", "int", "i2", "=", "0", ";", "WorldModel", ".", "Move", "temp", "=", "actionsOrder", "[", "i2", "]", ";", "actionsOrder", "[", "i2", "]", "=", "actionsOrder", "[", "i1", "]", ";", "actionsOrder", "[", "i1", "]", "=", "temp", ";", "boolean", "fencesAsObs", "=", "terms", ".", "length", ">", "5", "&&", "terms", "[", "5", "]", ".", "toString", "(", ")", ".", "equals", "(", "\"fences\"", ")", ";", "Search", "astar", "=", "new", "Search", "(", "model", ",", "from", ",", "to", ",", "actionsOrder", ",", "true", ",", "false", ",", "true", ",", "false", ",", "false", ",", "fencesAsObs", ",", "arch", ")", ";", "solution", "=", "astar", ".", "search", "(", ")", ";", "if", "(", "solution", "==", "null", "&&", "!", "fencesAsObs", ")", "{", "Search", "s", "=", "new", "Search", "(", "model", ",", "from", ",", "to", ",", "arch", ")", ";", "int", "fixtimes", "=", "0", ";", "while", "(", "s", ".", "search", "(", ")", "==", "null", "&&", "arch", ".", "isRunning", "(", ")", "&&", "fixtimes", "<", "100", ")", "{", "fixtimes", "++", ";", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "to", "+", "\"\"", ")", ";", "arch", ".", "obstaclePerceived", "(", "to", ".", "x", ",", "to", ".", "y", ")", ";", "to", "=", "model", ".", "nearFree", "(", "to", ",", "null", ")", ";", "s", "=", "new", "Search", "(", "model", ",", "from", ",", "to", ",", "arch", ")", ";", "}", "astar", "=", "new", "Search", "(", "model", ",", "from", ",", "to", ",", "actionsOrder", ",", "true", ",", "false", ",", "true", ",", "false", ",", "false", ",", "false", ",", "arch", ")", ";", "solution", "=", "astar", ".", "search", "(", ")", ";", "}", "}", "return", "solution", ";", "}", "}", "</s>" ]
9,114
[ "<s>", "package", "jia", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "io", ".", "Serializable", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collection", ";", "import", "java", ".", "util", ".", "List", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "final", "class", "Vec", "implements", "Serializable", ",", "Cloneable", ",", "Comparable", "<", "Vec", ">", "{", "public", "final", "double", "x", ",", "y", ";", "public", "final", "double", "r", ",", "t", ";", "public", "static", "final", "double", "PI2", "=", "2.0", "*", "Math", ".", "PI", ";", "public", "Vec", "(", "double", "x", ",", "double", "y", ")", "{", "this", ".", "x", "=", "x", ";", "this", ".", "y", "=", "y", ";", "this", ".", "r", "=", "Math", ".", "sqrt", "(", "x", "*", "x", "+", "y", "*", "y", ")", ";", "this", ".", "t", "=", "Math", ".", "atan2", "(", "y", ",", "x", ")", ";", "}", "public", "Vec", "(", "LocalWorldModel", "model", ",", "Location", "l", ")", "{", "this", ".", "x", "=", "l", ".", "x", ";", "this", ".", "y", "=", "model", ".", "getHeight", "(", ")", "-", "l", ".", "y", "-", "1", ";", "this", ".", "r", "=", "Math", ".", "sqrt", "(", "x", "*", "x", "+", "y", "*", "y", ")", ";", "this", ".", "t", "=", "Math", ".", "atan2", "(", "y", ",", "x", ")", ";", "}", "public", "Vec", "(", "LocalWorldModel", "model", ",", "int", "x", ",", "int", "y", ")", "{", "this", ".", "x", "=", "x", ";", "this", ".", "y", "=", "model", ".", "getHeight", "(", ")", "-", "y", "-", "1", ";", "this", ".", "r", "=", "Math", ".", "sqrt", "(", "x", "*", "x", "+", "this", ".", "y", "*", "this", ".", "y", ")", ";", "this", ".", "t", "=", "Math", ".", "atan2", "(", "this", ".", "y", ",", "x", ")", ";", "}", "public", "int", "getX", "(", ")", "{", "return", "(", "int", ")", "Math", ".", "round", "(", "x", ")", ";", "}", "public", "int", "getY", "(", ")", "{", "return", "(", "int", ")", "Math", ".", "round", "(", "y", ")", ";", "}", "public", "double", "magnitude", "(", ")", "{", "return", "r", ";", "}", "public", "double", "angle", "(", ")", "{", "return", "t", ";", "}", "public", "Location", "getLocation", "(", "LocalWorldModel", "model", ")", "{", "return", "new", "Location", "(", "getX", "(", ")", ",", "model", ".", "getHeight", "(", ")", "-", "getY", "(", ")", "-", "1", ")", ";", "}", "public", "Vec", "add", "(", "Vec", "v", ")", "{", "return", "new", "Vec", "(", "x", "+", "v", ".", "x", ",", "y", "+", "v", ".", "y", ")", ";", "}", "public", "Vec", "sub", "(", "Vec", "v", ")", "{", "return", "new", "Vec", "(", "x", "-", "v", ".", "x", ",", "y", "-", "v", ".", "y", ")", ";", "}", "public", "Vec", "product", "(", "double", "e", ")", "{", "return", "new", "Vec", "(", "x", "*", "e", ",", "y", "*", "e", ")", ";", "}", "public", "Vec", "newAngle", "(", "double", "t", ")", "{", "while", "(", "t", ">", "PI2", ")", "t", "=", "t", "-", "PI2", ";", "while", "(", "t", "<", "0", ")", "t", "=", "t", "+", "PI2", ";", "return", "new", "Vec", "(", "r", "*", "Math", ".", "cos", "(", "t", ")", ",", "r", "*", "Math", ".", "sin", "(", "t", ")", ")", ";", "}", "public", "Vec", "turn90CW", "(", ")", "{", "return", "new", "Vec", "(", "y", ",", "-", "x", ")", ";", "}", "public", "Vec", "turn90ACW", "(", ")", "{", "return", "new", "Vec", "(", "-", "y", ",", "x", ")", ";", "}", "public", "Vec", "newMagnitude", "(", "double", "r", ")", "{", "return", "new", "Vec", "(", "r", "*", "Math", ".", "cos", "(", "t", ")", ",", "r", "*", "Math", ".", "sin", "(", "t", ")", ")", ";", "}", "public", "int", "octant", "(", ")", "{", "double", "temp", "=", "t", "+", "Math", ".", "PI", "/", "8", ";", "if", "(", "temp", "<", "0", ")", "temp", "+=", "Math", ".", "PI", "*", "2", ";", "return", "(", "(", "int", ")", "(", "temp", "/", "(", "Math", ".", "PI", "/", "4", ")", ")", "%", "8", ")", ";", "}", "public", "int", "quadrant", "(", ")", "{", "double", "temp", "=", "t", "+", "Math", ".", "PI", "/", "4", ";", "if", "(", "temp", "<", "0", ")", "temp", "+=", "Math", ".", "PI", "*", "2", ";", "return", "(", "(", "int", ")", "(", "temp", "/", "(", "Math", ".", "PI", "/", "2", ")", ")", "%", "4", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "(", "int", ")", "(", "(", "x", "+", "y", ")", "*", "37", ")", ";", "}", "@", "Override", "public", "boolean", "equals", "(", "Object", "o", ")", "{", "if", "(", "o", "==", "null", ")", "return", "false", ";", "if", "(", "o", "==", "this", ")", "return", "true", ";", "if", "(", "o", "instanceof", "Vec", ")", "{", "Vec", "v", "=", "(", "Vec", ")", "o", ";", "return", "(", "getX", "(", ")", "==", "v", ".", "getX", "(", ")", ")", "&&", "(", "getY", "(", ")", "==", "v", ".", "getY", "(", ")", ")", ";", "}", "return", "false", ";", "}", "public", "int", "compareTo", "(", "Vec", "o", ")", "{", "if", "(", "r", ">", "o", ".", "r", ")", "return", "1", ";", "if", "(", "r", "<", "o", ".", "r", ")", "return", "-", "1", ";", "return", "0", ";", "}", "public", "Object", "clone", "(", ")", "{", "return", "this", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "getX", "(", ")", "+", "\",\"", "+", "getY", "(", ")", ";", "}", "public", "static", "Vec", "max", "(", "Collection", "<", "Vec", ">", "vs", ")", "{", "Vec", "max", "=", "null", ";", "for", "(", "Vec", "v", ":", "vs", ")", "{", "if", "(", "max", "==", "null", "||", "max", ".", "r", "<", "v", ".", "r", ")", "max", "=", "v", ";", "}", "return", "max", ";", "}", "public", "static", "List", "<", "Vec", ">", "sub", "(", "Collection", "<", "Vec", ">", "vs", ",", "Vec", "ref", ")", "{", "List", "<", "Vec", ">", "r", "=", "new", "ArrayList", "<", "Vec", ">", "(", "vs", ".", "size", "(", ")", ")", ";", "for", "(", "Vec", "v", ":", "vs", ")", "{", "r", ".", "add", "(", "v", ".", "sub", "(", "ref", ")", ")", ";", "}", "return", "r", ";", "}", "public", "static", "Vec", "mean", "(", "Collection", "<", "Vec", ">", "vs", ")", "{", "if", "(", "vs", ".", "isEmpty", "(", ")", ")", "return", "new", "Vec", "(", "0", ",", "0", ")", ";", "double", "x", "=", "0", ",", "y", "=", "0", ";", "for", "(", "Vec", "v", ":", "vs", ")", "{", "x", "+=", "v", ".", "x", ";", "y", "+=", "v", ".", "y", ";", "}", "return", "new", "Vec", "(", "x", "/", "vs", ".", "size", "(", ")", ",", "y", "/", "vs", ".", "size", "(", ")", ")", ";", "}", "public", "static", "Vec", "stddev", "(", "Collection", "<", "Vec", ">", "vs", ",", "Vec", "mean", ")", "{", "if", "(", "vs", ".", "isEmpty", "(", ")", ")", "return", "new", "Vec", "(", "0", ",", "0", ")", ";", "double", "x", "=", "0", ",", "y", "=", "0", ";", "for", "(", "Vec", "v", ":", "vs", ")", "{", "x", "+=", "Math", ".", "pow", "(", "v", ".", "x", "-", "mean", ".", "x", ",", "2", ")", ";", "y", "+=", "Math", ".", "pow", "(", "v", ".", "y", "-", "mean", ".", "y", ",", "2", ")", ";", "}", "x", "=", "x", "/", "vs", ".", "size", "(", ")", ";", "y", "=", "y", "/", "vs", ".", "size", "(", ")", ";", "return", "new", "Vec", "(", "Math", ".", "sqrt", "(", "x", ")", ",", "Math", ".", "sqrt", "(", "y", ")", ")", ";", "}", "public", "double", "dot", "(", "Vec", "a", ")", "{", "return", "x", "*", "a", ".", "y", "-", "y", "*", "a", ".", "x", ";", "}", "}", "</s>" ]
9,115
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "other_side_fence", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "int", "fx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "fy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "Vec", "vtarget", "=", "computesOtherSide", "(", "model", ",", "new", "Vec", "(", "model", ",", "model", ".", "getAgPos", "(", "arch", ".", "getMyId", "(", ")", ")", ")", ",", "new", "Vec", "(", "model", ",", "fx", ",", "fy", ")", ")", ";", "Location", "ltarget", "=", "vtarget", ".", "getLocation", "(", "model", ")", ";", "ltarget", "=", "model", ".", "nearFree", "(", "ltarget", ",", "null", ")", ";", "return", "un", ".", "unifies", "(", "terms", "[", "2", "]", ",", "ASSyntax", ".", "createNumber", "(", "ltarget", ".", "x", ")", ")", "&&", "un", ".", "unifies", "(", "terms", "[", "3", "]", ",", "ASSyntax", ".", "createNumber", "(", "ltarget", ".", "y", ")", ")", ";", "}", "public", "Vec", "computesOtherSide", "(", "LocalWorldModel", "model", ",", "Vec", "start", ",", "Vec", "fence", ")", "{", "return", "fence", ".", "sub", "(", "start", ")", ".", "product", "(", "6", ")", ".", "add", "(", "start", ")", ";", "}", "}", "</s>" ]
9,116
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "NumberTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "Structure", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "env", ".", "WorldModel", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "near_least_visited", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "try", "{", "LocalWorldModel", "model", "=", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ";", "if", "(", "model", "==", "null", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ")", ";", "}", "else", "{", "int", "agx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "agy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "Location", "ag", "=", "new", "Location", "(", "agx", ",", "agy", ")", ";", "Structure", "sarea", "=", "(", "Structure", ")", "args", "[", "2", "]", ";", "int", "ax1", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "sarea", ".", "getTerm", "(", "0", ")", ")", ".", "solve", "(", ")", ";", "int", "ay1", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "sarea", ".", "getTerm", "(", "1", ")", ")", ".", "solve", "(", ")", ";", "int", "ax2", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "sarea", ".", "getTerm", "(", "2", ")", ")", ".", "solve", "(", ")", ";", "int", "ay2", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "sarea", ".", "getTerm", "(", "3", ")", ")", ".", "solve", "(", ")", ";", "Location", "tl", "=", "new", "Location", "(", "ax1", ",", "ay1", ")", ";", "Location", "br", "=", "new", "Location", "(", "ax2", ",", "ay2", ")", ";", "Location", "n", "=", "model", ".", "getNearLeastVisited", "(", "ag", ",", "tl", ",", "br", ")", ";", "if", "(", "n", "!=", "null", ")", "{", "Search", "s", "=", "new", "Search", "(", "model", ",", "ag", ",", "n", ",", "ts", ".", "getUserAgArch", "(", ")", ")", ";", "int", "loopcount", "=", "0", ";", "while", "(", "s", ".", "search", "(", ")", "==", "null", "&&", "ts", ".", "getUserAgArch", "(", ")", ".", "isRunning", "(", ")", "&&", "loopcount", "<", "5", ")", "{", "loopcount", "++", ";", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "n", "+", "\"\"", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "n", ")", ";", "n", "=", "model", ".", "getNearLeastVisited", "(", "ag", ",", "tl", ",", "br", ")", ";", "s", "=", "new", "Search", "(", "model", ",", "ag", ",", "n", ",", "ts", ".", "getUserAgArch", "(", ")", ")", ";", "}", "un", ".", "unifies", "(", "args", "[", "3", "]", ",", "new", "NumberTermImpl", "(", "n", ".", "x", ")", ")", ";", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "new", "NumberTermImpl", "(", "n", ".", "y", ")", ")", ";", "return", "true", ";", "}", "else", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "ag", "+", "\"", "area,", "tl=\"", "+", "tl", "+", "\"", "br=\"", "+", "br", ")", ";", "}", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "}", "</s>" ]
9,117
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "ListTerm", ";", "import", "jason", ".", "asSyntax", ".", "ListTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "IClusterModel", ";", "import", "env", ".", "WorldModel", ";", "import", "env", ".", "ClusterModel", ";", "public", "class", "position_to_cluster", "extends", "DefaultInternalAction", "{", "private", "static", "final", "long", "serialVersionUID", "=", "1L", ";", "static", "Logger", "logger", "=", "null", ";", "private", "double", "angular_dis_bet_ag", "=", "140.0", "*", "Math", ".", "PI", "/", "180.0", ";", "private", "double", "ct", "=", "1", ";", "LocalWorldModel", "model", ";", "CowboyArch", "arch", ";", "Search", "s", ";", "int", "[", "]", "radius", ";", "int", "n", ";", "List", "<", "Nodo", ">", "path", ";", "IClusterModel", "cModel", ";", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "logger", "==", "null", ")", "logger", "=", "ts", ".", "getLogger", "(", ")", ";", "if", "(", "cModel", "==", "null", ")", "cModel", "=", "ClusterModelFactory", ".", "getModel", "(", "ts", ".", "getUserAgArch", "(", ")", ".", "getAgName", "(", ")", ")", ";", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "Vec", "dir", "=", "new", "Vec", "(", "0", ",", "0", ")", ";", "model", "=", "arch", ".", "getModel", "(", ")", ";", "ListTerm", "pos", "=", "new", "ListTermImpl", "(", ")", ";", "Vec", "[", "]", "centers", "=", "cModel", ".", "getCenters", "(", ")", ";", "radius", "=", "cModel", ".", "getMaxDist", "(", ")", ";", "if", "(", "args", "[", "0", "]", ".", "isNumeric", "(", ")", "&&", "args", "[", "1", "]", ".", "isNumeric", "(", ")", "&&", "args", "[", "2", "]", ".", "isNumeric", "(", ")", ")", "{", "n", "=", "0", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "int", "dist", "=", "centers", "[", "0", "]", ".", "getLocation", "(", "model", ")", ".", "distanceChebyshev", "(", "new", "Location", "(", "x", ",", "y", ")", ")", ";", "int", "dist2", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "centers", ".", "length", ";", "i", "++", ")", "{", "dist2", "=", "centers", "[", "i", "]", ".", "getLocation", "(", "model", ")", ".", "distanceChebyshev", "(", "new", "Location", "(", "x", ",", "y", ")", ")", ";", "if", "(", "dist2", "<", "dist", ")", "{", "dist", "=", "dist2", ";", "n", "=", "i", ";", "}", "}", "int", "numAg", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "dir", "=", "getDirection", "(", "centers", "[", "n", "]", ")", ".", "newMagnitude", "(", "(", "double", ")", "radius", "[", "n", "]", "*", "cModel", ".", "getPrefkPTC", "(", ")", ")", ";", "Location", "[", "]", "positions", "=", "new", "Location", "[", "numAg", "]", ";", "if", "(", "numAg", "==", "1", ")", "{", "positions", "[", "0", "]", "=", "centers", "[", "n", "]", ".", "sub", "(", "dir", ")", ".", "getLocation", "(", "model", ")", ";", "}", "else", "{", "double", "angle", "=", "(", "(", "new", "Vec", "(", "0", ",", "0", ")", ")", ".", "sub", "(", "dir", ")", ")", ".", "t", "-", "angular_dis_bet_ag", "/", "2.0", ";", "double", "angle_step", "=", "angular_dis_bet_ag", "/", "(", "(", "double", ")", "numAg", "-", "1.0", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numAg", ";", "i", "++", ")", "{", "Vec", "temp", "=", "dir", ";", "temp", "=", "dir", ".", "newAngle", "(", "angle_step", "*", "(", "double", ")", "i", "+", "angle", ")", ";", "positions", "[", "i", "]", "=", "firstFreeLoc", "(", "temp", ",", "centers", "[", "n", "]", ")", ";", "}", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numAg", ";", "i", "++", ")", "{", "pos", ".", "add", "(", "ASSyntax", ".", "createStructure", "(", "\"pos\"", ",", "ASSyntax", ".", "createNumber", "(", "positions", "[", "i", "]", ".", "x", ")", ",", "ASSyntax", ".", "createNumber", "(", "positions", "[", "i", "]", ".", "y", ")", ")", ")", ";", "}", "}", "else", "{", "ts", ".", "getAg", "(", ")", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "3", "]", ",", "pos", ")", ";", "}", "private", "Vec", "getDirection", "(", "Vec", "from", ")", "throws", "Exception", "{", "s", "=", "new", "Search", "(", "model", ",", "from", ".", "getLocation", "(", "model", ")", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "arch", ")", ";", "path", "=", "Search", ".", "normalPath", "(", "s", ".", "search", "(", ")", ")", ";", "int", "n", "=", "path", ".", "size", "(", ")", ";", "Location", "temp", ";", "if", "(", "n", "+", "1", ">", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ".", "distanceChebyshev", "(", "from", ".", "getLocation", "(", "model", ")", ")", "&&", "n", ">", "4", ")", "{", "temp", "=", "Search", ".", "getNodeLocation", "(", "path", ".", "get", "(", "4", ")", ")", ";", "}", "else", "{", "System", ".", "out", ".", "println", "(", "\"\"", ")", ";", "temp", "=", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ";", "}", "Vec", "tempvec", "=", "new", "Vec", "(", "model", ",", "temp", ")", ";", "return", "tempvec", ".", "sub", "(", "from", ")", ";", "}", "private", "void", "printNodes", "(", "List", "<", "Nodo", ">", "path", ")", "{", "for", "(", "Nodo", "no", ":", "path", ")", "{", "System", ".", "out", ".", "println", "(", "\"CLUSTER", "___", "\"", "+", "Search", ".", "getNodeLocation", "(", "no", ")", ")", ";", "}", "}", "private", "Location", "firstFreeLoc", "(", "Vec", "displacement", ",", "Vec", "Origin", ")", "{", "Location", "loc", "=", "Origin", ".", "getLocation", "(", "model", ")", ";", "int", "maxSize", "=", "(", "int", ")", "displacement", ".", "r", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "maxSize", ";", "i", "++", ")", "{", "Location", "temp", "=", "(", "displacement", ".", "newMagnitude", "(", "i", ")", ")", ".", "add", "(", "Origin", ")", ".", "getLocation", "(", "model", ")", ";", "if", "(", "(", "!", "model", ".", "inGrid", "(", "temp", ")", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "temp", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "temp", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "SWITCH", ",", "temp", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "temp", ")", ")", "{", "return", "loc", ";", "}", "loc", "=", "temp", ";", "}", "return", "loc", ";", "}", "}", "</s>" ]
9,118
[ "<s>", "package", "jia", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "jason", ".", "asSemantics", ".", "*", ";", "import", "jason", ".", "asSyntax", ".", "*", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "fence_switch", "extends", "DefaultInternalAction", "{", "private", "static", "final", "long", "serialVersionUID", "=", "1L", ";", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "try", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "int", "i", ",", "j", ",", "posx", "=", "0", ",", "posy", "=", "0", ";", "boolean", "ind", "=", "false", ";", "for", "(", "i", "=", "-", "1", ";", "i", "<=", "1", ";", "i", "++", ")", "{", "for", "(", "j", "=", "-", "1", ";", "j", "<=", "1", ";", "j", "++", ")", "{", "if", "(", "i", "==", "0", "&&", "j", "==", "0", ")", "continue", ";", "posx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", "+", "i", ";", "posy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", "+", "j", ";", "while", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "posx", ",", "posy", ")", ")", "{", "posx", "+=", "i", ";", "posy", "+=", "j", ";", "}", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "SWITCH", ",", "posx", ",", "posy", ")", ")", "{", "ind", "=", "true", ";", "break", ";", "}", "}", "if", "(", "ind", ")", "break", ";", "}", "if", "(", "ind", ")", "{", "ts", ".", "getAg", "(", ")", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "posx", "+", "\",\"", "+", "posy", "+", "\")\"", ")", ";", "return", "un", ".", "unifies", "(", "args", "[", "2", "]", ",", "ASSyntax", ".", "createNumber", "(", "posx", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "3", "]", ",", "ASSyntax", ".", "createNumber", "(", "posy", ")", ")", ";", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "}", "</s>" ]
9,119
[ "<s>", "package", "jia", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "busca", ".", "Nodo", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "env", ".", "ClusterModel", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "IClusterModel", ";", "import", "env", ".", "WorldModel", ";", "import", "jason", ".", "*", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "jason", ".", "asSemantics", ".", "*", ";", "import", "jason", ".", "asSyntax", ".", "*", ";", "public", "class", "weight_of_clusters", "extends", "DefaultInternalAction", "{", "private", "static", "final", "long", "serialVersionUID", "=", "7875071367882251756L", ";", "LocalWorldModel", "model", ";", "static", "Logger", "logger", ";", "Search", "s", ";", "CowboyArch", "arch", ";", "int", "size", ";", "IClusterModel", "ClModel", ";", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "ClModel", "==", "null", ")", "ClModel", "=", "ClusterModelFactory", ".", "getModel", "(", "ts", ".", "getUserAgArch", "(", ")", ".", "getAgName", "(", ")", ")", ";", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "model", "=", "arch", ".", "getModel", "(", ")", ";", "Location", "Cl", "=", "new", "Location", "(", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ",", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ")", ";", "Location", "Gr", "=", "new", "Location", "(", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "2", "]", ")", ".", "solve", "(", ")", ",", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "3", "]", ")", ".", "solve", "(", ")", ")", ";", "int", "S", "=", "getSParameter", "(", "Cl", ",", "ts", ")", ";", "int", "L", "=", "getDistances", "(", "Cl", ",", "Gr", ")", ";", "if", "(", "args", ".", "length", "==", "8", "&&", "args", "[", "4", "]", ".", "isGround", "(", ")", "&&", "args", "[", "5", "]", ".", "isGround", "(", ")", ")", "{", "Location", "actCl", "=", "new", "Location", "(", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "4", "]", ")", ".", "solve", "(", ")", ",", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "5", "]", ")", ".", "solve", "(", ")", ")", ";", "double", "resp", "=", "Math", ".", "abs", "(", "(", "double", ")", "S", "*", "L", "/", "100", ")", "+", "1.0", "/", "(", "1.0", "+", "(", "double", ")", "actCl", ".", "distanceChebyshev", "(", "Cl", ")", ")", ";", "return", "un", ".", "unifies", "(", "args", "[", "6", "]", ",", "new", "NumberTermImpl", "(", "resp", ")", ")", "&", "un", ".", "unifies", "(", "args", "[", "7", "]", ",", "new", "NumberTermImpl", "(", "size", ")", ")", ";", "}", "else", "if", "(", "args", ".", "length", "==", "8", ")", "{", "double", "resp", "=", "Math", ".", "abs", "(", "(", "double", ")", "S", "*", "L", "/", "100", ")", ";", "return", "un", ".", "unifies", "(", "args", "[", "6", "]", ",", "new", "NumberTermImpl", "(", "resp", ")", ")", "&", "un", ".", "unifies", "(", "args", "[", "7", "]", ",", "new", "NumberTermImpl", "(", "size", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "new", "NumberTermImpl", "(", "Math", ".", "abs", "(", "(", "double", ")", "S", "*", "L", "/", "100", ")", ")", ")", "&", "un", ".", "unifies", "(", "args", "[", "5", "]", ",", "new", "NumberTermImpl", "(", "size", ")", ")", ";", "}", "private", "int", "getDistances", "(", "Location", "Cl", ",", "Location", "Gr", ")", "throws", "Exception", "{", "s", "=", "new", "Search", "(", "model", ",", "Cl", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "arch", ")", ";", "List", "<", "Nodo", ">", "path", "=", "Search", ".", "normalPath", "(", "s", ".", "search", "(", ")", ")", ";", "int", "ClToCo", "=", "path", ".", "size", "(", ")", ";", "s", "=", "new", "Search", "(", "model", ",", "Gr", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "arch", ")", ";", "path", "=", "Search", ".", "normalPath", "(", "s", ".", "search", "(", ")", ")", ";", "int", "GrToCl", "=", "path", ".", "size", "(", ")", ";", "return", "ClToCo", "+", "GrToCl", ";", "}", "private", "int", "getSParameter", "(", "Location", "Cl", ",", "TransitionSystem", "ts", ")", "{", "Vec", "[", "]", "Centers", "=", "ClModel", ".", "getCenters", "(", ")", ";", "int", "[", "]", "Radius", "=", "ClModel", ".", "getMaxDist", "(", ")", ";", "int", "[", "]", "NumberOfCows", "=", "ClModel", ".", "getNumCows", "(", ")", ";", "int", "dist", "=", "Centers", "[", "0", "]", ".", "getLocation", "(", "model", ")", ".", "distanceChebyshev", "(", "Cl", ")", ";", "int", "k", "=", "0", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "Centers", ".", "length", ";", "i", "++", ")", "{", "if", "(", "dist", ">", "Centers", "[", "i", "]", ".", "getLocation", "(", "model", ")", ".", "distanceChebyshev", "(", "Cl", ")", ")", "{", "dist", "=", "Centers", "[", "i", "]", ".", "getLocation", "(", "model", ")", ".", "distanceChebyshev", "(", "Cl", ")", ";", "k", "=", "i", ";", "}", "}", "size", "=", "Radius", "[", "k", "]", ";", "return", "(", "Radius", "[", "k", "]", "-", "ClModel", ".", "getPrefRadius", "(", ")", ")", "*", "(", "NumberOfCows", "[", "k", "]", "-", "ClModel", ".", "getPrefNCows", "(", ")", ")", ";", "}", "}", "</s>" ]
9,120
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "arch", ".", "CowboyArch", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "corral", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "WorldModel", "model", "=", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "return", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "x", ",", "y", ")", ";", "}", "}", "</s>" ]
9,121
[ "<s>", "package", "jia", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "env", ".", "ClusterModel", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "IClusterModel", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "ListTerm", ";", "import", "jason", ".", "asSyntax", ".", "ListTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "public", "class", "getclusters", "extends", "DefaultInternalAction", "{", "static", "Logger", "logger", "=", "null", ";", "IClusterModel", "cM", ";", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "logger", "==", "null", ")", "logger", "=", "ts", ".", "getLogger", "(", ")", ";", "if", "(", "cM", "==", "null", ")", "cM", "=", "ClusterModelFactory", ".", "getModel", "(", "ts", ".", "getUserAgArch", "(", ")", ".", "getAgName", "(", ")", ")", ";", "Vec", "[", "]", "Center", "=", "cM", ".", "getCenters", "(", ")", ";", "int", "n", "=", "cM", ".", "getNumberOfCluster", "(", ")", ";", "int", "[", "]", "maxDist", "=", "cM", ".", "getMaxDist", "(", ")", ";", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "ListTerm", "Cl", "=", "new", "ListTermImpl", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "Location", "l", "=", "Center", "[", "i", "]", ".", "getLocation", "(", "model", ")", ";", "logger", ".", "info", "(", "\"\"", "+", "n", "+", "\"\"", "+", "i", "+", "\"th", "is", "at", "(\"", "+", "l", ".", "x", "+", "\",\"", "+", "l", ".", "y", "+", "\")\"", ")", ";", "Cl", ".", "add", "(", "ASSyntax", ".", "createStructure", "(", "\"pos\"", ",", "ASSyntax", ".", "createNumber", "(", "l", ".", "x", ")", ",", "ASSyntax", ".", "createNumber", "(", "l", ".", "y", ")", ")", ")", ";", "}", "ListTerm", "Sizes", "=", "new", "ListTermImpl", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "Sizes", ".", "add", "(", "ASSyntax", ".", "createNumber", "(", "maxDist", "[", "i", "]", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "0", "]", ",", "ASSyntax", ".", "createNumber", "(", "n", ")", ")", "&", "un", ".", "unifies", "(", "args", "[", "1", "]", ",", "Cl", "!=", "null", "&&", "!", "(", "Cl", ".", "size", "(", ")", ">", "0", ")", "?", "Cl", ".", "get", "(", "0", ")", ":", "Cl", ")", "&", "un", ".", "unifies", "(", "args", "[", "2", "]", ",", "Sizes", ")", ";", "}", "}", "</s>" ]
9,122
[ "<s>", "package", "jia", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createNumber", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createStructure", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "ListTerm", ";", "import", "jason", ".", "asSyntax", ".", "ListTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "ObjectTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "Structure", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collection", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "cluster", "extends", "DefaultInternalAction", "{", "public", "static", "final", "int", "COWS_BY_BOY", "=", "6", ";", "public", "static", "final", "int", "MAXCLUSTERSIZE", "=", "(", "7", "*", "COWS_BY_BOY", ")", "-", "2", ";", "static", "Logger", "logger", "=", "null", ";", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "logger", "==", "null", ")", "logger", "=", "ts", ".", "getLogger", "(", ")", ";", "try", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "if", "(", "model", "==", "null", ")", "return", "false", ";", "List", "<", "Location", ">", "locs", "=", "getCluster", "(", "model", ",", "3", ",", "arch", ")", ";", "if", "(", "args", ".", "length", "==", "1", ")", "{", "return", "un", ".", "unifies", "(", "args", "[", "0", "]", ",", "new", "ObjectTermImpl", "(", "locs", ")", ")", ";", "}", "else", "{", "Structure", "nearCow", "=", "null", ";", "ListTerm", "r", "=", "new", "ListTermImpl", "(", ")", ";", "ListTerm", "tail", "=", "r", ";", "for", "(", "Location", "l", ":", "locs", ")", "{", "Structure", "pos", "=", "createStructure", "(", "\"pos\"", ",", "createNumber", "(", "l", ".", "x", ")", ",", "createNumber", "(", "l", ".", "y", ")", ")", ";", "tail", "=", "tail", ".", "append", "(", "pos", ")", ";", "if", "(", "nearCow", "==", "null", ")", "nearCow", "=", "pos", ";", "}", "if", "(", "args", ".", "length", ">", "2", "&&", "nearCow", "!=", "null", ")", "un", ".", "unifies", "(", "args", "[", "2", "]", ",", "nearCow", ")", ";", "return", "un", ".", "unifies", "(", "args", "[", "0", "]", ",", "new", "ObjectTermImpl", "(", "locs", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "1", "]", ",", "r", ")", ";", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "public", "static", "List", "<", "Location", ">", "getCluster", "(", "LocalWorldModel", "model", ",", "int", "maxDist", ",", "CowboyArch", "arch", ")", "throws", "Exception", "{", "Collection", "<", "Vec", ">", "cows", "=", "model", ".", "getKnownCows", "(", ")", ";", "List", "<", "Vec", ">", "vs", "=", "new", "ArrayList", "<", "Vec", ">", "(", ")", ";", "Location", "center", "=", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ";", "Vec", "near", "=", "null", ";", "int", "nearDist", "=", "0", ";", "for", "(", "Vec", "v", ":", "cows", ")", "{", "Location", "cl", "=", "v", ".", "getLocation", "(", "model", ")", ";", "if", "(", "!", "model", ".", "getCorral", "(", ")", ".", "contains", "(", "cl", ")", ")", "{", "vs", ".", "add", "(", "v", ")", ";", "int", "dist", "=", "model", ".", "pathLength", "(", "cl", ",", "center", ",", "false", ",", "arch", ")", ";", "if", "(", "dist", ">=", "0", ")", "{", "if", "(", "near", "==", "null", "||", "dist", "<", "nearDist", ")", "{", "near", "=", "v", ";", "nearDist", "=", "dist", ";", "}", "}", "}", "}", "List", "<", "Vec", ">", "cs", "=", "new", "ArrayList", "<", "Vec", ">", "(", ")", ";", "if", "(", "near", "!=", "null", ")", "{", "vs", ".", "remove", "(", "near", ")", ";", "cs", ".", "add", "(", "near", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"\"", "+", "model", ".", "getKnownCows", "(", ")", ")", ";", "}", "boolean", "add", "=", "true", ";", "while", "(", "add", ")", "{", "add", "=", "false", ";", "Iterator", "<", "Vec", ">", "i", "=", "vs", ".", "iterator", "(", ")", ";", "while", "(", "i", ".", "hasNext", "(", ")", ")", "{", "Vec", "v", "=", "i", ".", "next", "(", ")", ";", "Iterator", "<", "Vec", ">", "j", "=", "cs", ".", "iterator", "(", ")", ";", "while", "(", "j", ".", "hasNext", "(", ")", "&&", "cs", ".", "size", "(", ")", "<", "MAXCLUSTERSIZE", ")", "{", "Vec", "c", "=", "j", ".", "next", "(", ")", ";", "if", "(", "c", ".", "sub", "(", "v", ")", ".", "magnitude", "(", ")", "<", "maxDist", ")", "{", "cs", ".", "add", "(", "v", ")", ";", "i", ".", "remove", "(", ")", ";", "add", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "cs", ".", "size", "(", ")", ">", "MAXCLUSTERSIZE", ")", "break", ";", "}", "List", "<", "Location", ">", "clusterLocs", "=", "new", "ArrayList", "<", "Location", ">", "(", ")", ";", "for", "(", "Vec", "v", ":", "cs", ")", "{", "clusterLocs", ".", "add", "(", "v", ".", "getLocation", "(", "model", ")", ")", ";", "}", "return", "clusterLocs", ";", "}", "public", "static", "List", "<", "Location", ">", "getCluster2008", "(", "LocalWorldModel", "model", ",", "int", "maxDist", ",", "CowboyArch", "arch", ")", "throws", "Exception", "{", "Collection", "<", "Vec", ">", "cows", "=", "model", ".", "getKnownCows", "(", ")", ";", "System", ".", "out", ".", "println", "(", "cows", ")", ";", "List", "<", "Vec", ">", "cs", "=", "new", "ArrayList", "<", "Vec", ">", "(", ")", ";", "Vec", "mean", "=", "Vec", ".", "mean", "(", "cows", ")", ";", "List", "<", "Vec", ">", "vs", "=", "new", "ArrayList", "<", "Vec", ">", "(", ")", ";", "for", "(", "Vec", "v", ":", "cows", ")", "{", "Location", "cl", "=", "v", ".", "getLocation", "(", "model", ")", ";", "if", "(", "!", "model", ".", "getCorral", "(", ")", ".", "contains", "(", "cl", ")", ")", "{", "Vec", "vc", "=", "v", ".", "sub", "(", "mean", ")", ";", "vs", ".", "add", "(", "vc", ")", ";", "}", "else", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "v", "+", "\"\"", ")", ";", "}", "}", "if", "(", "vs", ".", "size", "(", ")", ">", "4", ")", "Collections", ".", "sort", "(", "vs", ")", ";", "if", "(", "!", "vs", ".", "isEmpty", "(", ")", ")", "cs", ".", "add", "(", "vs", ".", "remove", "(", "0", ")", ")", ";", "boolean", "add", "=", "true", ";", "while", "(", "add", ")", "{", "add", "=", "false", ";", "Iterator", "<", "Vec", ">", "i", "=", "vs", ".", "iterator", "(", ")", ";", "while", "(", "i", ".", "hasNext", "(", ")", ")", "{", "Vec", "v", "=", "i", ".", "next", "(", ")", ";", "Iterator", "<", "Vec", ">", "j", "=", "cs", ".", "iterator", "(", ")", ";", "while", "(", "j", ".", "hasNext", "(", ")", "&&", "cs", ".", "size", "(", ")", "<", "MAXCLUSTERSIZE", ")", "{", "Vec", "c", "=", "j", ".", "next", "(", ")", ";", "if", "(", "c", ".", "sub", "(", "v", ")", ".", "magnitude", "(", ")", "<", "maxDist", ")", "{", "cs", ".", "add", "(", "v", ")", ";", "i", ".", "remove", "(", ")", ";", "add", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "cs", ".", "size", "(", ")", ">", "MAXCLUSTERSIZE", ")", "break", ";", "}", "List", "<", "Location", ">", "clusterLocs", "=", "new", "ArrayList", "<", "Location", ">", "(", ")", ";", "for", "(", "Vec", "v", ":", "cs", ")", "{", "clusterLocs", ".", "add", "(", "v", ".", "add", "(", "mean", ")", ".", "getLocation", "(", "model", ")", ")", ";", "}", "return", "clusterLocs", ";", "}", "public", "static", "List", "<", "Vec", ">", "location2vec", "(", "LocalWorldModel", "model", ",", "List", "<", "Location", ">", "clusterLocs", ")", "{", "List", "<", "Vec", ">", "cows", "=", "new", "ArrayList", "<", "Vec", ">", "(", ")", ";", "for", "(", "Location", "l", ":", "clusterLocs", ")", "cows", ".", "add", "(", "new", "Vec", "(", "model", ",", "l", ")", ")", ";", "return", "cows", ";", "}", "}", "</s>" ]
9,123
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "arch", ".", "CowboyArch", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "obstacle", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "WorldModel", "model", "=", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "return", "!", "model", ".", "inGrid", "(", "x", ",", "y", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "x", ",", "y", ")", ";", "}", "}", "</s>" ]
9,124
[ "<s>", "package", "jia", ";", "import", "env", ".", "WorldModel", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "fence", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "LocalWorldModel", "model", "=", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "y", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "return", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "x", ",", "y", ")", ";", "}", "}", "</s>" ]
9,125
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "List", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "has_object_in_path", "extends", "direction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "Nodo", "solution", "=", "findPath", "(", "ts", ",", "terms", ")", ";", "if", "(", "solution", "!=", "null", ")", "{", "int", "object", "=", "WorldModel", ".", "stringToObject", "(", "terms", "[", "4", "]", ".", "toString", "(", ")", ".", "toUpperCase", "(", ")", ")", ";", "if", "(", "object", "<", "0", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "terms", "[", "4", "]", "+", "\"\"", ")", ";", "return", "false", ";", "}", "List", "<", "Nodo", ">", "path", "=", "Search", ".", "normalPath", "(", "solution", ")", ";", "for", "(", "Nodo", "n", ":", "path", ")", "{", "Location", "l", "=", "Search", ".", "getNodeLocation", "(", "n", ")", ";", "if", "(", "model", ".", "hasObject", "(", "object", ",", "l", ")", ")", "{", "return", "un", ".", "unifies", "(", "terms", "[", "5", "]", ",", "ASSyntax", ".", "createNumber", "(", "l", ".", "x", ")", ")", "&&", "un", ".", "unifies", "(", "terms", "[", "6", "]", ",", "ASSyntax", ".", "createNumber", "(", "l", ".", "y", ")", ")", "&&", "un", ".", "unifies", "(", "terms", "[", "7", "]", ",", "ASSyntax", ".", "createNumber", "(", "n", ".", "getProfundidade", "(", ")", ")", ")", ";", "}", "}", "}", "else", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "terms", "[", "0", "]", "+", "\",\"", "+", "terms", "[", "1", "]", "+", "\"", "to", "\"", "+", "terms", "[", "2", "]", "+", "\",\"", "+", "terms", "[", "3", "]", "+", "\"\"", ")", ";", "}", "return", "false", ";", "}", "}", "</s>" ]
9,126
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "is_corral_switch", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "{", "LocalWorldModel", "model", "=", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ";", "int", "sx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "sy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "sx", "+", "1", ",", "sy", ")", ")", "return", "true", ";", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "sx", "-", "1", ",", "sy", ")", ")", "return", "true", ";", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "sx", ",", "sy", "+", "1", ")", ")", "return", "true", ";", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "sx", ",", "sy", "-", "1", ")", ")", "return", "true", ";", "return", "false", ";", "}", "}", "</s>" ]
9,127
[ "<s>", "package", "jia", ";", "import", "jason", ".", "JasonException", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "java", ".", "util", ".", "Random", ";", "import", "java", ".", "util", ".", "Iterator", ";", "public", "class", "random", "extends", "DefaultInternalAction", "{", "private", "Random", "random", "=", "new", "Random", "(", ")", ";", "@", "Override", "public", "Object", "execute", "(", "final", "TransitionSystem", "ts", ",", "final", "Unifier", "un", ",", "final", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "try", "{", "if", "(", "!", "args", "[", "0", "]", ".", "isVar", "(", ")", ")", "{", "throw", "new", "JasonException", "(", "\"\"", ")", ";", "}", "if", "(", "!", "args", "[", "1", "]", ".", "isNumeric", "(", ")", ")", "{", "throw", "new", "JasonException", "(", "\"\"", ")", ";", "}", "final", "int", "max", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "final", "int", "maxIter", "=", "args", ".", "length", "<", "3", "?", "Integer", ".", "MAX_VALUE", ":", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "return", "new", "Iterator", "<", "Unifier", ">", "(", ")", "{", "int", "i", "=", "0", ";", "public", "boolean", "hasNext", "(", ")", "{", "return", "i", "<", "maxIter", "&&", "ts", ".", "getUserAgArch", "(", ")", ".", "isRunning", "(", ")", ";", "}", "public", "Unifier", "next", "(", ")", "{", "i", "++", ";", "Unifier", "c", "=", "un", ".", "clone", "(", ")", ";", "c", ".", "unifies", "(", "args", "[", "0", "]", ",", "new", "NumberTermImpl", "(", "random", ".", "nextInt", "(", "max", ")", ")", ")", ";", "return", "c", ";", "}", "public", "void", "remove", "(", ")", "{", "}", "}", ";", "}", "catch", "(", "ArrayIndexOutOfBoundsException", "e", ")", "{", "throw", "new", "JasonException", "(", "\"\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "JasonException", "(", "\"\"", "+", "e", ",", "e", ")", ";", "}", "}", "}", "</s>" ]
9,128
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "NumberTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "public", "class", "dist", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "int", "iagx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "iagy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "int", "itox", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "int", "itoy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "3", "]", ")", ".", "solve", "(", ")", ";", "int", "dist", "=", "new", "Location", "(", "iagx", ",", "iagy", ")", ".", "maxBorder", "(", "new", "Location", "(", "itox", ",", "itoy", ")", ")", ";", "return", "un", ".", "unifies", "(", "terms", "[", "4", "]", ",", "new", "NumberTermImpl", "(", "dist", ")", ")", ";", "}", "}", "</s>" ]
9,129
[ "<s>", "package", "jia", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createNumber", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "env", ".", "WorldModel", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "switch_places", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "try", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "if", "(", "model", "==", "null", ")", "return", "false", ";", "int", "lx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "ly", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "int", "agx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "int", "agy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "3", "]", ")", ".", "solve", "(", ")", ";", "Location", "agPlace", "=", "new", "Location", "(", "agx", ",", "agy", ")", ";", "Location", "place1", "=", "null", ",", "place2", "=", "null", ";", "if", "(", "model", ".", "isHorizontalFence", "(", "lx", ",", "ly", ")", ")", "{", "place1", "=", "new", "Location", "(", "lx", ",", "ly", "+", "1", ")", ";", "place2", "=", "new", "Location", "(", "lx", ",", "ly", "-", "1", ")", ";", "}", "else", "{", "place1", "=", "new", "Location", "(", "lx", "+", "1", ",", "ly", ")", ";", "place2", "=", "new", "Location", "(", "lx", "-", "1", ",", "ly", ")", ";", "}", "int", "distPlace1", "=", "model", ".", "pathLength", "(", "agPlace", ",", "place1", ",", "false", ",", "arch", ")", ";", "int", "distPlace2", "=", "model", ".", "pathLength", "(", "agPlace", ",", "place2", ",", "false", ",", "arch", ")", ";", "if", "(", "distPlace1", ">", "distPlace2", "|", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "place1", ")", ")", "{", "Location", "bak", "=", "place2", ";", "place2", "=", "place1", ";", "place1", "=", "bak", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "createNumber", "(", "place1", ".", "x", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "5", "]", ",", "createNumber", "(", "place1", ".", "y", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "6", "]", ",", "createNumber", "(", "place2", ".", "x", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "7", "]", ",", "createNumber", "(", "place2", ".", "y", ")", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "}", "</s>" ]
9,130
[ "<s>", "package", "jia", ";", "import", "jason", ".", "architecture", ".", "AgArch", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "Comparator", ";", "import", "java", ".", "util", ".", "LinkedList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "busca", ".", "AEstrela", ";", "import", "busca", ".", "Busca", ";", "import", "busca", ".", "Estado", ";", "import", "busca", ".", "Heuristica", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "IClusterModel", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "Search", "{", "public", "static", "final", "int", "DIST_FOR_AG_OBSTACLE", "=", "2", ";", "private", "int", "sizeOfCluster", "=", "-", "1", ";", "final", "LocalWorldModel", "model", ";", "final", "Location", "from", ",", "to", ";", "final", "boolean", "considerAgentsAsObstacles", ";", "final", "boolean", "considerCorralAsObstacles", ";", "final", "boolean", "considerCowsAsObstacles", ";", "final", "boolean", "considerRepulsionForCows", ";", "final", "boolean", "considerEnemyCorralRepulsion", ";", "final", "boolean", "considerFenceAsObstacle", ";", "int", "maxDistFromCluster", ";", "WorldModel", ".", "Move", "[", "]", "actionsOrder", ";", "int", "nbStates", "=", "0", ";", "AgArch", "agArch", ";", "public", "static", "final", "WorldModel", ".", "Move", "[", "]", "defaultActions", "=", "{", "WorldModel", ".", "Move", ".", "west", ",", "WorldModel", ".", "Move", ".", "east", ",", "WorldModel", ".", "Move", ".", "north", ",", "WorldModel", ".", "Move", ".", "northeast", ",", "WorldModel", ".", "Move", ".", "northwest", ",", "WorldModel", ".", "Move", ".", "south", ",", "WorldModel", ".", "Move", ".", "southeast", ",", "WorldModel", ".", "Move", ".", "southwest", "}", ";", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "Search", ".", "class", ".", "getName", "(", ")", ")", ";", "public", "Search", "(", "LocalWorldModel", "m", ",", "Location", "from", ",", "Location", "to", ",", "WorldModel", ".", "Move", "[", "]", "actions", ",", "boolean", "considerAgentsAsObstacles", ",", "boolean", "considerCorralAsObstacles", ",", "boolean", "considerCowsAsObstacles", ",", "boolean", "considerRepulsionForCows", ",", "boolean", "considerEnemyCorralRepulsion", ",", "boolean", "considerFenceAsObstacle", ",", "AgArch", "agArch", ")", "{", "this", ".", "model", "=", "m", ";", "this", ".", "from", "=", "from", ";", "this", ".", "to", "=", "to", ";", "this", ".", "considerAgentsAsObstacles", "=", "considerAgentsAsObstacles", ";", "this", ".", "considerCorralAsObstacles", "=", "considerCorralAsObstacles", ";", "this", ".", "considerCowsAsObstacles", "=", "considerCowsAsObstacles", ";", "this", ".", "considerRepulsionForCows", "=", "considerRepulsionForCows", ";", "this", ".", "considerEnemyCorralRepulsion", "=", "considerEnemyCorralRepulsion", ";", "this", ".", "considerFenceAsObstacle", "=", "considerFenceAsObstacle", ";", "this", ".", "agArch", "=", "agArch", ";", "if", "(", "actions", "!=", "null", ")", "this", ".", "actionsOrder", "=", "actions", ";", "else", "this", ".", "actionsOrder", "=", "defaultActions", ";", "this", ".", "maxDistFromCluster", "=", "4", ";", "this", ".", "nbStates", "=", "0", ";", "model", ".", "getKnownCows", "(", ")", ";", "}", "public", "void", "setMaxDistFromCluster", "(", "int", "m", ")", "{", "maxDistFromCluster", "=", "m", ";", "}", "Search", "(", "LocalWorldModel", "m", ",", "Location", "from", ",", "Location", "to", ",", "AgArch", "agArch", ")", "{", "this", "(", "m", ",", "from", ",", "to", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "agArch", ")", ";", "}", "public", "void", "setSearchWithCluster", "(", "int", "a", ")", "{", "sizeOfCluster", "=", "a", ";", "}", "public", "Nodo", "search", "(", ")", "throws", "Exception", "{", "Busca", "searchAlg", "=", "new", "AEstrela", "(", ")", ";", "GridState", "root", "=", "new", "GridState", "(", "from", ",", "WorldModel", ".", "Move", ".", "skip", ",", "this", ")", ";", "root", ".", "distFromCluster", "=", "sizeOfCluster", ";", "root", ".", "setAsRoot", "(", ")", ";", "return", "searchAlg", ".", "busca", "(", "root", ")", ";", "}", "public", "static", "List", "<", "Nodo", ">", "normalPath", "(", "Nodo", "n", ")", "{", "List", "<", "Nodo", ">", "r", "=", "new", "LinkedList", "<", "Nodo", ">", "(", ")", ";", "while", "(", "n", "!=", "null", ")", "{", "r", ".", "add", "(", "0", ",", "n", ")", ";", "n", "=", "n", ".", "getPai", "(", ")", ";", "}", "return", "r", ";", "}", "public", "static", "Location", "getNodeLocation", "(", "Nodo", "n", ")", "{", "return", "(", "(", "GridState", ")", "n", ".", "getEstado", "(", ")", ")", ".", "pos", ";", "}", "public", "static", "WorldModel", ".", "Move", "firstAction", "(", "Nodo", "solution", ")", "{", "Nodo", "root", "=", "solution", ";", "Estado", "prev1", "=", "null", ";", "Estado", "prev2", "=", "null", ";", "while", "(", "root", "!=", "null", ")", "{", "prev2", "=", "prev1", ";", "prev1", "=", "root", ".", "getEstado", "(", ")", ";", "root", "=", "root", ".", "getPai", "(", ")", ";", "}", "if", "(", "prev2", "!=", "null", ")", "{", "return", "(", "(", "GridState", ")", "prev2", ")", ".", "op", ";", "}", "return", "null", ";", "}", "}", "final", "class", "GridState", "implements", "Estado", ",", "Heuristica", "{", "int", "distFromCluster", "=", "-", "1", ";", "final", "Location", "pos", ";", "final", "WorldModel", ".", "Move", "op", ";", "final", "Search", "ia", ";", "final", "int", "hashCode", ";", "boolean", "isRoot", "=", "false", ";", "public", "GridState", "(", "Location", "l", ",", "WorldModel", ".", "Move", "op", ",", "Search", "ia", ")", "{", "this", ".", "pos", "=", "l", ";", "this", ".", "op", "=", "op", ";", "this", ".", "ia", "=", "ia", ";", "hashCode", "=", "pos", ".", "hashCode", "(", ")", ";", "ia", ".", "nbStates", "++", ";", "}", "public", "void", "setAsRoot", "(", ")", "{", "isRoot", "=", "true", ";", "}", "public", "int", "custo", "(", ")", "{", "if", "(", "isRoot", ")", "return", "0", ";", "int", "c", "=", "1", ";", "if", "(", "ia", ".", "considerCowsAsObstacles", ")", "c", "+=", "ia", ".", "model", ".", "getCowsRep", "(", "pos", ".", "x", ",", "pos", ".", "y", ")", ";", "if", "(", "ia", ".", "considerRepulsionForCows", ")", "{", "c", "+=", "ia", ".", "model", ".", "getObsRep", "(", "pos", ".", "x", ",", "pos", ".", "y", ")", ";", "}", "if", "(", "ia", ".", "considerEnemyCorralRepulsion", ")", "c", "+=", "ia", ".", "model", ".", "getEnemyCorralRep", "(", "pos", ".", "x", ",", "pos", ".", "y", ")", ";", "if", "(", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "pos", ".", "x", ",", "pos", ".", "y", ")", ")", "c", "+=", "5", ";", "return", "c", ";", "}", "public", "boolean", "ehMeta", "(", ")", "{", "return", "pos", ".", "equals", "(", "ia", ".", "to", ")", ";", "}", "public", "String", "getDescricao", "(", ")", "{", "return", "\"Grid", "search\"", ";", "}", "public", "int", "h", "(", ")", "{", "return", "pos", ".", "maxBorder", "(", "ia", ".", "to", ")", ";", "}", "public", "List", "<", "Estado", ">", "sucessores", "(", ")", "{", "List", "<", "Estado", ">", "s", "=", "new", "ArrayList", "<", "Estado", ">", "(", ")", ";", "if", "(", "ia", ".", "nbStates", ">", "100000", ")", "{", "ia", ".", "logger", ".", "info", "(", "\"\"", ")", ";", "return", "s", ";", "}", "else", "if", "(", "ia", ".", "agArch", "!=", "null", "&&", "!", "ia", ".", "agArch", ".", "isRunning", "(", ")", ")", "{", "return", "s", ";", "}", "for", "(", "int", "a", "=", "0", ";", "a", "<", "ia", ".", "actionsOrder", ".", "length", ";", "a", "++", ")", "{", "suc", "(", "s", ",", "WorldModel", ".", "getNewLocationForAction", "(", "pos", ",", "ia", ".", "actionsOrder", "[", "a", "]", ")", ",", "ia", ".", "actionsOrder", "[", "a", "]", ")", ";", "}", "if", "(", "isRoot", ")", "{", "Collections", ".", "sort", "(", "s", ",", "new", "VisitedComparator", "(", "ia", ".", "model", ")", ")", ";", "}", "return", "s", ";", "}", "private", "void", "suc", "(", "List", "<", "Estado", ">", "s", ",", "Location", "newl", ",", "WorldModel", ".", "Move", "op", ")", "{", "if", "(", "!", "ia", ".", "model", ".", "inGrid", "(", "newl", ")", ")", "return", ";", "if", "(", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "newl", ")", ")", "return", ";", "if", "(", "ia", ".", "considerCorralAsObstacles", "&&", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "newl", ")", ")", "return", ";", "if", "(", "ia", ".", "considerAgentsAsObstacles", ")", "{", "if", "(", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "AGENT", ",", "newl", ")", "&&", "ia", ".", "from", ".", "maxBorder", "(", "newl", ")", "<=", "Search", ".", "DIST_FOR_AG_OBSTACLE", ")", "return", ";", "if", "(", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "ENEMY", ",", "newl", ")", "&&", "ia", ".", "from", ".", "maxBorder", "(", "newl", ")", "<=", "1", ")", "return", ";", "}", "if", "(", "ia", ".", "considerCowsAsObstacles", "&&", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "COW", ",", "newl", ")", "&&", "ia", ".", "from", ".", "maxBorder", "(", "newl", ")", "<=", "Search", ".", "DIST_FOR_AG_OBSTACLE", ")", "return", ";", "if", "(", "ia", ".", "considerFenceAsObstacle", "&&", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "newl", ".", "x", ",", "newl", ".", "y", ")", ")", "return", ";", "if", "(", "distFromCluster", "!=", "-", "1", ")", "{", "if", "(", "ia", ".", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "newl", ")", "&&", "ia", ".", "from", ".", "maxBorder", "(", "newl", ")", "<=", "distFromCluster", ")", "{", "return", ";", "}", "return", ";", "}", "s", ".", "add", "(", "new", "GridState", "(", "newl", ",", "op", ",", "ia", ")", ")", ";", "}", "public", "boolean", "equals", "(", "Object", "o", ")", "{", "if", "(", "o", "!=", "null", "&&", "o", "instanceof", "GridState", ")", "{", "GridState", "m", "=", "(", "GridState", ")", "o", ";", "return", "pos", ".", "equals", "(", "m", ".", "pos", ")", ";", "}", "return", "false", ";", "}", "public", "int", "hashCode", "(", ")", "{", "return", "hashCode", ";", "}", "public", "String", "toString", "(", ")", "{", "return", "\"(\"", "+", "pos", "+", "\"-\"", "+", "op", "+", "\")\"", ";", "}", "}", "class", "VisitedComparator", "implements", "Comparator", "<", "Estado", ">", "{", "LocalWorldModel", "model", ";", "VisitedComparator", "(", "LocalWorldModel", "m", ")", "{", "model", "=", "m", ";", "}", "public", "int", "compare", "(", "Estado", "o1", ",", "Estado", "o2", ")", "{", "int", "v1", "=", "model", ".", "getVisited", "(", "(", "(", "GridState", ")", "o1", ")", ".", "pos", ")", ";", "int", "v2", "=", "model", ".", "getVisited", "(", "(", "(", "GridState", ")", "o2", ")", ".", "pos", ")", ";", "if", "(", "v1", ">", "v2", ")", "return", "1", ";", "if", "(", "v2", ">", "v1", ")", "return", "-", "1", ";", "return", "0", ";", "}", "}", "</s>" ]
9,131
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "NumberTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "path_length", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "try", "{", "LocalWorldModel", "model", "=", "(", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ")", ".", "getModel", "(", ")", ";", "int", "iagx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "iagy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "int", "itox", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "int", "itoy", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "terms", "[", "3", "]", ")", ".", "solve", "(", ")", ";", "if", "(", "model", ".", "inGrid", "(", "itox", ",", "itoy", ")", ")", "{", "while", "(", "!", "model", ".", "isFreeOfObstacle", "(", "itox", ",", "itoy", ")", "&&", "itox", ">", "0", ")", "itox", "--", ";", "while", "(", "!", "model", ".", "isFreeOfObstacle", "(", "itox", ",", "itoy", ")", "&&", "itox", "<", "model", ".", "getWidth", "(", ")", ")", "itox", "++", ";", "Location", "from", "=", "new", "Location", "(", "iagx", ",", "iagy", ")", ";", "Location", "to", "=", "new", "Location", "(", "itox", ",", "itoy", ")", ";", "boolean", "fencesAsObs", "=", "terms", ".", "length", ">", "5", "&&", "terms", "[", "5", "]", ".", "toString", "(", ")", ".", "equals", "(", "\"fences\"", ")", ";", "int", "dist", "=", "model", ".", "pathLength", "(", "from", ",", "to", ",", "fencesAsObs", ",", "ts", ".", "getUserAgArch", "(", ")", ")", ";", "if", "(", "dist", ">=", "0", ")", "{", "return", "un", ".", "unifies", "(", "terms", "[", "4", "]", ",", "new", "NumberTermImpl", "(", "dist", ")", ")", ";", "}", "else", "if", "(", "!", "fencesAsObs", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "from", "+", "\"", "to", "\"", "+", "to", "+", "\"!\"", ")", ";", "}", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "}", "</s>" ]
9,132
[ "<s>", "package", "jia", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createNumber", ";", "import", "static", "jason", ".", "asSyntax", ".", "ASSyntax", ".", "createStructure", ";", "import", "jason", ".", "JasonException", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "ListTerm", ";", "import", "jason", ".", "asSyntax", ".", "ListTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "NumberTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "ObjectTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "jason", ".", "stdlib", ".", "foreach", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "sun", ".", "font", ".", "EAttribute", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "herd_position", "extends", "DefaultInternalAction", "{", "public", "static", "final", "int", "agDistanceInFormation", "=", "3", ";", "public", "enum", "Formation", "{", "one", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "0", ",", "0", ")", "}", ";", "}", "}", ",", "two", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "sd", "+", "1", ",", "0", ")", ",", "new", "Vec", "(", "-", "sd", ",", "0", ")", "}", ";", "}", "}", ",", "three", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "0", ",", "0", ")", ",", "new", "Vec", "(", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "-", "d", ",", "-", "1", ")", "}", ";", "}", "}", ",", "four", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "sd", "+", "1", ",", "0", ")", ",", "new", "Vec", "(", "-", "sd", ",", "0", ")", ",", "new", "Vec", "(", "d", "+", "sd", ",", "-", "3", ")", ",", "new", "Vec", "(", "-", "(", "d", "+", "sd", ")", ",", "-", "3", ")", "}", ";", "}", "}", ",", "five", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "0", ",", "0", ")", ",", "new", "Vec", "(", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "-", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "d", "*", "2", "-", "1", ",", "-", "4", ")", ",", "new", "Vec", "(", "-", "d", "*", "2", ",", "-", "4", ")", "}", ";", "}", "}", ",", "six", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "sd", "+", "1", ",", "0", ")", ",", "new", "Vec", "(", "-", "sd", ",", "0", ")", ",", "new", "Vec", "(", "d", "+", "sd", ",", "-", "3", ")", ",", "new", "Vec", "(", "-", "(", "d", "+", "sd", ")", ",", "-", "3", ")", ",", "new", "Vec", "(", "d", "*", "2", "+", "sd", "-", "2", ",", "-", "6", ")", ",", "new", "Vec", "(", "-", "(", "d", "*", "2", "+", "sd", "-", "2", ")", ",", "-", "6", ")", "}", ";", "}", "}", ",", "seven", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "0", ",", "0", ")", ",", "new", "Vec", "(", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "-", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "d", "*", "2", "-", "1", ",", "-", "4", ")", ",", "new", "Vec", "(", "-", "d", "*", "2", ",", "-", "4", ")", ",", "new", "Vec", "(", "d", "*", "3", "-", "1", ",", "-", "6", ")", ",", "new", "Vec", "(", "-", "d", "*", "3", ",", "-", "6", ")", "}", ";", "}", "}", ",", "eight", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "sd", "+", "1", ",", "0", ")", ",", "new", "Vec", "(", "-", "sd", ",", "0", ")", ",", "new", "Vec", "(", "d", "+", "sd", ",", "-", "3", ")", ",", "new", "Vec", "(", "-", "(", "d", "+", "sd", ")", ",", "-", "3", ")", ",", "new", "Vec", "(", "d", "*", "2", "+", "sd", "-", "2", ",", "-", "6", ")", ",", "new", "Vec", "(", "-", "(", "d", "*", "2", "+", "sd", "-", "2", ")", ",", "-", "6", ")", ",", "new", "Vec", "(", "d", "*", "3", "+", "sd", "-", "2", ",", "-", "8", ")", ",", "new", "Vec", "(", "-", "(", "d", "*", "3", "+", "sd", "-", "2", ")", ",", "-", "8", ")", "}", ";", "}", "}", ",", "nine", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "0", ",", "0", ")", ",", "new", "Vec", "(", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "-", "d", ",", "-", "1", ")", ",", "new", "Vec", "(", "d", "*", "2", "-", "1", ",", "-", "4", ")", ",", "new", "Vec", "(", "-", "d", "*", "2", ",", "-", "4", ")", ",", "new", "Vec", "(", "d", "*", "3", "-", "1", ",", "-", "6", ")", ",", "new", "Vec", "(", "-", "d", "*", "3", ",", "-", "6", ")", ",", "new", "Vec", "(", "d", "*", "4", "-", "1", ",", "-", "8", ")", ",", "new", "Vec", "(", "-", "d", "*", "4", ",", "-", "8", ")", "}", ";", "}", "}", ",", "ten", "{", "Vec", "[", "]", "getDistances", "(", ")", "{", "return", "new", "Vec", "[", "]", "{", "new", "Vec", "(", "sd", "+", "1", ",", "0", ")", ",", "new", "Vec", "(", "-", "sd", ",", "0", ")", ",", "new", "Vec", "(", "d", "+", "sd", ",", "-", "3", ")", ",", "new", "Vec", "(", "-", "(", "d", "+", "sd", ")", ",", "-", "3", ")", ",", "new", "Vec", "(", "d", "*", "2", "+", "sd", "-", "2", ",", "-", "6", ")", ",", "new", "Vec", "(", "-", "(", "d", "*", "2", "+", "sd", "-", "2", ")", ",", "-", "6", ")", ",", "new", "Vec", "(", "d", "*", "3", "+", "sd", "-", "2", ",", "-", "8", ")", ",", "new", "Vec", "(", "-", "(", "d", "*", "3", "+", "sd", "-", "2", ")", ",", "-", "8", ")", ",", "new", "Vec", "(", "d", "*", "4", "+", "sd", "-", "2", ",", "-", "10", ")", ",", "new", "Vec", "(", "-", "(", "d", "*", "4", "+", "sd", "-", "2", ")", ",", "-", "10", ")", "}", ";", "}", "}", ";", "abstract", "Vec", "[", "]", "getDistances", "(", ")", ";", "private", "static", "final", "int", "d", "=", "agDistanceInFormation", ";", "private", "static", "final", "int", "sd", "=", "agDistanceInFormation", "/", "2", ";", "}", ";", "LocalWorldModel", "model", ";", "List", "<", "Location", ">", "lastCluster", "=", "null", ";", "public", "void", "setModel", "(", "LocalWorldModel", "model", ")", "{", "this", ".", "model", "=", "model", ";", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "try", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "model", "=", "arch", ".", "getModel", "(", ")", ";", "if", "(", "model", "==", "null", ")", "return", "false", ";", "Location", "agLoc", "=", "model", ".", "getAgPos", "(", "arch", ".", "getMyId", "(", ")", ")", ";", "if", "(", "agLoc", "==", "null", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", ")", ";", "return", "false", ";", "}", "Formation", "formation", "=", "Formation", ".", "six", ";", "if", "(", "args", "[", "0", "]", ".", "isNumeric", "(", ")", ")", "{", "int", "index", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "formation", "=", "Formation", ".", "values", "(", ")", "[", "index", "-", "1", "]", ";", "}", "else", "{", "formation", "=", "Formation", ".", "valueOf", "(", "args", "[", "0", "]", ".", "toString", "(", ")", ")", ";", "}", "List", "<", "Location", ">", "clusterLocs", "=", "(", "List", "<", "Location", ">", ")", "(", "(", "ObjectTerm", ")", "args", "[", "1", "]", ")", ".", "getObject", "(", ")", ";", "if", "(", "arch", ".", "hasGUI", "(", ")", ")", "setFormationLoc", "(", "clusterLocs", ",", "formation", ")", ";", "if", "(", "args", ".", "length", "==", "4", ")", "{", "Location", "agTarget", "=", "getAgTarget", "(", "clusterLocs", ",", "formation", ",", "agLoc", ")", ";", "if", "(", "agTarget", "!=", "null", ")", "{", "return", "un", ".", "unifies", "(", "args", "[", "2", "]", ",", "new", "NumberTermImpl", "(", "agTarget", ".", "x", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "3", "]", ",", "new", "NumberTermImpl", "(", "agTarget", ".", "y", ")", ")", ";", "}", "else", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "agLoc", "+", "\"", "places", "are", "\"", "+", "formationPlaces", "(", "clusterLocs", ",", "formation", ")", "+", "\"", "cluster", "is", "\"", "+", "lastCluster", ")", ";", "}", "}", "else", "{", "List", "<", "Location", ">", "locs", "=", "formationPlaces", "(", "clusterLocs", ",", "formation", ")", ";", "if", "(", "locs", "!=", "null", "&&", "locs", ".", "size", "(", ")", ">", "0", ")", "{", "ListTerm", "r", "=", "new", "ListTermImpl", "(", ")", ";", "ListTerm", "tail", "=", "r", ";", "for", "(", "Location", "l", ":", "locs", ")", "{", "tail", "=", "tail", ".", "append", "(", "createStructure", "(", "\"pos\"", ",", "createNumber", "(", "l", ".", "x", ")", ",", "createNumber", "(", "l", ".", "y", ")", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "2", "]", ",", "r", ")", ";", "}", "else", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", "+", "agLoc", "+", "\"", "places", "are", "\"", "+", "formationPlaces", "(", "clusterLocs", ",", "formation", ")", ")", ";", "}", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "public", "Location", "getAgTarget", "(", "List", "<", "Location", ">", "clusterLocs", ",", "Formation", "formation", ",", "Location", "ag", ")", "throws", "Exception", "{", "Location", "r", "=", "null", ";", "List", "<", "Location", ">", "locs", "=", "formationPlaces", "(", "clusterLocs", ",", "formation", ")", ";", "if", "(", "locs", "!=", "null", ")", "{", "for", "(", "Location", "l", ":", "locs", ")", "{", "if", "(", "ag", ".", "equals", "(", "l", ")", "||", "!", "model", ".", "hasObject", "(", "WorldModel", ".", "AGENT", ",", "l", ")", ")", "{", "r", "=", "l", ";", "break", ";", "}", "}", "}", "if", "(", "r", "!=", "null", ")", "r", "=", "model", ".", "nearFree", "(", "r", ",", "null", ")", ";", "return", "r", ";", "}", "public", "void", "setFormationLoc", "(", "List", "<", "Location", ">", "clusterLocs", ",", "Formation", "formation", ")", "throws", "Exception", "{", "model", ".", "removeAll", "(", "WorldModel", ".", "FORPLACE", ")", ";", "List", "<", "Location", ">", "locs", "=", "formationPlaces", "(", "clusterLocs", ",", "formation", ")", ";", "if", "(", "locs", "!=", "null", ")", "{", "for", "(", "Location", "l", ":", "locs", ")", "{", "if", "(", "model", ".", "inGrid", "(", "l", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "FORPLACE", ",", "l", ")", ";", "}", "}", "}", "}", "public", "List", "<", "Location", ">", "formationPlaces", "(", "List", "<", "Location", ">", "clusterLocs", ",", "Formation", "formation", ")", "throws", "Exception", "{", "lastCluster", "=", "clusterLocs", ";", "List", "<", "Vec", ">", "cows", "=", "cluster", ".", "location2vec", "(", "model", ",", "clusterLocs", ")", ";", "if", "(", "cows", ".", "isEmpty", "(", ")", ")", "return", "null", ";", "Vec", "mean", "=", "Vec", ".", "mean", "(", "cows", ")", ";", "int", "stepsFromCenter", "=", "Math", ".", "max", "(", "4", ",", "(", "int", ")", "Math", ".", "round", "(", "Vec", ".", "max", "(", "cows", ")", ".", "sub", "(", "mean", ")", ".", "magnitude", "(", ")", ")", "+", "1", ")", ";", "Search", "s", "=", "new", "Search", "(", "model", ",", "mean", ".", "getLocation", "(", "model", ")", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "null", ")", ";", "s", ".", "setMaxDistFromCluster", "(", "stepsFromCenter", "+", "Search", ".", "DIST_FOR_AG_OBSTACLE", ")", ";", "List", "<", "Nodo", ">", "np", "=", "Search", ".", "normalPath", "(", "s", ".", "search", "(", ")", ")", ";", "int", "n", "=", "Math", ".", "min", "(", "stepsFromCenter", ",", "np", ".", "size", "(", ")", ")", ";", "if", "(", "n", "==", "0", ")", "throw", "new", "JasonException", "(", "\"\"", "+", "clusterLocs", "+", "\"", "cows:\"", "+", "cows", ")", ";", "Vec", "cowstarget", "=", "new", "Vec", "(", "model", ",", "Search", ".", "getNodeLocation", "(", "np", ".", "get", "(", "n", ")", ")", ")", ";", "Vec", "farcow", "=", "null", ";", "for", "(", "Vec", "c", ":", "cows", ")", "if", "(", "farcow", "==", "null", "||", "farcow", ".", "getLocation", "(", "model", ")", ".", "maxBorder", "(", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ")", "<", "c", ".", "getLocation", "(", "model", ")", ".", "maxBorder", "(", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ")", ")", "farcow", "=", "c", ";", "Vec", "agsTarget", "=", "mean", ".", "sub", "(", "cowstarget", ")", ".", "newMagnitude", "(", "farcow", ".", "sub", "(", "mean", ")", ".", "magnitude", "(", ")", "+", "1", ")", ";", "List", "<", "Location", ">", "r", "=", "new", "ArrayList", "<", "Location", ">", "(", ")", ";", "for", "(", "Vec", "position", ":", "formation", ".", "getDistances", "(", ")", ")", "{", "Location", "l", "=", "findFirstFreeLocTowardsTarget", "(", "agsTarget", ",", "position", ",", "mean", ",", "false", ",", "model", ")", ";", "if", "(", "l", "==", "null", ")", "{", "l", "=", "model", ".", "nearFree", "(", "agsTarget", ".", "add", "(", "mean", ")", ".", "getLocation", "(", "model", ")", ",", "r", ")", ";", "}", "else", "{", "if", "(", "formation", "==", "Formation", ".", "one", "||", "formation", "==", "Formation", ".", "two", ")", "l", "=", "pathToNearCow", "(", "l", ",", "clusterLocs", ")", ";", "if", "(", "!", "model", ".", "inGrid", "(", "l", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", "||", "r", ".", "contains", "(", "l", ")", ")", "l", "=", "model", ".", "nearFree", "(", "l", ",", "r", ")", ";", "}", "r", ".", "add", "(", "l", ")", ";", "}", "return", "r", ";", "}", "public", "static", "Location", "findFirstFreeLocTowardsTarget", "(", "Vec", "start", ",", "Vec", "direction", ",", "Vec", "ref", ",", "boolean", "fenceAsObs", ",", "LocalWorldModel", "model", ")", "{", "Vec", "startandref", "=", "start", ".", "add", "(", "ref", ")", ";", "Vec", "t", "=", "start", ".", "turn90CW", "(", ")", ";", "t", "=", "t", ".", "newAngle", "(", "t", ".", "angle", "(", ")", "+", "direction", ".", "angle", "(", ")", ")", ";", "int", "maxSize", "=", "(", "int", ")", "direction", ".", "magnitude", "(", ")", ";", "Location", "l", "=", "t", ".", "newMagnitude", "(", "maxSize", ")", ".", "add", "(", "startandref", ")", ".", "getLocation", "(", "model", ")", ";", "Location", "lastloc", "=", "null", ";", "for", "(", "int", "s", "=", "1", ";", "s", "<=", "maxSize", ";", "s", "++", ")", "{", "l", "=", "t", ".", "newMagnitude", "(", "s", ")", ".", "add", "(", "startandref", ")", ".", "getLocation", "(", "model", ")", ";", "if", "(", "(", "!", "model", ".", "inGrid", "(", "l", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "CORRAL", ",", "l", ")", ")", "&&", "lastloc", "!=", "null", ")", "return", "lastloc", ";", "if", "(", "fenceAsObs", "&&", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "l", ")", "&&", "lastloc", "!=", "null", ")", "return", "lastloc", ";", "lastloc", "=", "l", ";", "}", "return", "l", ";", "}", "private", "Location", "pathToNearCow", "(", "Location", "t", ",", "List", "<", "Location", ">", "cows", ")", "{", "Location", "near", "=", "null", ";", "for", "(", "Location", "c", ":", "cows", ")", "{", "if", "(", "near", "==", "null", "||", "t", ".", "maxBorder", "(", "c", ")", "<", "t", ".", "maxBorder", "(", "near", ")", ")", "near", "=", "c", ";", "}", "if", "(", "near", "!=", "null", "&&", "t", ".", "maxBorder", "(", "near", ")", ">", "WorldModel", ".", "cowPerceptionRatio", ")", "{", "Vec", "nearcv", "=", "new", "Vec", "(", "model", ",", "near", ")", ";", "Vec", "dircow", "=", "new", "Vec", "(", "model", ",", "t", ")", ".", "sub", "(", "nearcv", ")", ";", "for", "(", "int", "s", "=", "1", ";", "s", "<=", "3", ";", "s", "++", ")", "{", "Location", "l", "=", "dircow", ".", "newMagnitude", "(", "s", ")", ".", "add", "(", "nearcv", ")", ".", "getLocation", "(", "model", ")", ";", "if", "(", "!", "model", ".", "hasObject", "(", "WorldModel", ".", "COW", ",", "l", ")", ")", "return", "l", ";", "}", "}", "return", "t", ";", "}", "}", "</s>" ]
9,133
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "NumberTermImpl", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "public", "class", "scouter_pos", "extends", "DefaultInternalAction", "{", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "try", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "LocalWorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "if", "(", "model", "==", "null", ")", "return", "false", ";", "int", "lx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ";", "int", "ly", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ";", "int", "tx", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "2", "]", ")", ".", "solve", "(", ")", ";", "int", "ty", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "3", "]", ")", ".", "solve", "(", ")", ";", "Location", "leaderPos", "=", "new", "Location", "(", "lx", ",", "ly", ")", ";", "Location", "leaderTarget", "=", "new", "Location", "(", "tx", ",", "ty", ")", ";", "Location", "agTarget", "=", "getScouterTarget", "(", "model", ",", "leaderPos", ",", "leaderTarget", ")", ";", "if", "(", "agTarget", "!=", "null", ")", "{", "return", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "new", "NumberTermImpl", "(", "agTarget", ".", "x", ")", ")", "&&", "un", ".", "unifies", "(", "args", "[", "5", "]", ",", "new", "NumberTermImpl", "(", "agTarget", ".", "y", ")", ")", ";", "}", "else", "{", "ts", ".", "getLogger", "(", ")", ".", "info", "(", "\"\"", ")", ";", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "public", "Location", "getScouterTarget", "(", "LocalWorldModel", "model", ",", "Location", "leaderPos", ",", "Location", "leaderTarget", ")", "throws", "Exception", "{", "Vec", "leader", "=", "new", "Vec", "(", "model", ",", "leaderPos", ")", ";", "Vec", "target", "=", "new", "Vec", "(", "model", ",", "leaderTarget", ")", ".", "sub", "(", "leader", ")", ";", "Vec", "me", "=", "new", "Vec", "(", "model", ".", "agPerceptionRatio", "*", "2", "-", "3", ",", "0", ")", ";", "return", "model", ".", "nearFree", "(", "herd_position", ".", "findFirstFreeLocTowardsTarget", "(", "target", ",", "me", ",", "leader", ",", "true", ",", "model", ")", ",", "null", ")", ";", "}", "}", "</s>" ]
9,134
[ "<s>", "package", "jia", ";", "import", "java", ".", "util", ".", "Arrays", ";", "import", "java", ".", "util", ".", "Comparator", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "IClusterModel", ";", "import", "busca", ".", "Nodo", ";", "import", "arch", ".", "CowboyArch", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "jason", ".", "asSemantics", ".", "*", ";", "import", "jason", ".", "asSyntax", ".", "*", ";", "public", "class", "preferable_cluster", "extends", "DefaultInternalAction", "{", "private", "static", "final", "long", "serialVersionUID", "=", "-", "1652602575376052947L", ";", "LocalWorldModel", "model", ";", "static", "Logger", "logger", ";", "Search", "s", ";", "CowboyArch", "arch", ";", "int", "size", ";", "IClusterModel", "ClModel", ";", "int", "n", "=", "20", ";", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "args", ")", "throws", "Exception", "{", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "model", "=", "arch", ".", "getModel", "(", ")", ";", "if", "(", "ClModel", "==", "null", ")", "ClModel", "=", "ClusterModelFactory", ".", "getModel", "(", "ts", ".", "getUserAgArch", "(", ")", ".", "getAgName", "(", ")", ")", ";", "Location", "Gr", "=", "new", "Location", "(", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "0", "]", ")", ".", "solve", "(", ")", ",", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "1", "]", ")", ".", "solve", "(", ")", ")", ";", "ListTerm", "pos", "=", "new", "ListTermImpl", "(", ")", ";", "ListTerm", "sizs", "=", "new", "ListTermImpl", "(", ")", ";", "if", "(", "args", ".", "length", "==", "5", ")", "{", "contCluster", "[", "]", "ClChosed", "=", "getClusterWith", "(", "null", ",", "Gr", ")", ";", "if", "(", "ClChosed", ".", "length", ">", "0", ")", "{", "contCluster", "cCl", "=", "nearCorralCluster", "(", "ClChosed", ")", ";", "Location", "loc", "=", "cCl", ".", "v", ".", "getLocation", "(", "model", ")", ";", "pos", ".", "add", "(", "ASSyntax", ".", "createStructure", "(", "\"pos\"", ",", "ASSyntax", ".", "createNumber", "(", "loc", ".", "x", ")", ",", "ASSyntax", ".", "createNumber", "(", "loc", ".", "y", ")", ")", ")", ";", "sizs", ".", "add", "(", "ASSyntax", ".", "createNumber", "(", "cCl", ".", "d", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "2", "]", ",", "pos", ")", "&", "un", ".", "unifies", "(", "args", "[", "3", "]", ",", "sizs", ")", "&", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "new", "NumberTermImpl", "(", "1", ")", ")", ";", "}", "else", "if", "(", "args", ".", "length", "==", "7", ")", "{", "if", "(", "args", "[", "2", "]", ".", "isGround", "(", ")", "&&", "args", "[", "3", "]", ".", "isGround", "(", ")", ")", "{", "Location", "Cl", "=", "new", "Location", "(", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "2", "]", ")", ".", "solve", "(", ")", ",", "(", "int", ")", "(", "(", "NumberTerm", ")", "args", "[", "3", "]", ")", ".", "solve", "(", ")", ")", ";", "contCluster", "[", "]", "ClChosed", "=", "getClusterWith", "(", "Cl", ",", "Gr", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ClChosed", ".", "length", ";", "i", "++", ")", "{", "Location", "loc", "=", "ClChosed", "[", "i", "]", ".", "v", ".", "getLocation", "(", "model", ")", ";", "pos", ".", "add", "(", "ASSyntax", ".", "createStructure", "(", "\"pos\"", ",", "ASSyntax", ".", "createNumber", "(", "loc", ".", "x", ")", ",", "ASSyntax", ".", "createNumber", "(", "loc", ".", "y", ")", ")", ")", ";", "sizs", ".", "add", "(", "ASSyntax", ".", "createNumber", "(", "ClChosed", "[", "i", "]", ".", "d", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "pos", ")", "&", "un", ".", "unifies", "(", "args", "[", "5", "]", ",", "sizs", ")", "&", "un", ".", "unifies", "(", "args", "[", "6", "]", ",", "new", "NumberTermImpl", "(", "ClChosed", ".", "length", ")", ")", ";", "}", "contCluster", "[", "]", "ClChosed", "=", "getClusterWith", "(", "null", ",", "Gr", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ClChosed", ".", "length", ";", "i", "++", ")", "{", "Location", "loc", "=", "ClChosed", "[", "i", "]", ".", "v", ".", "getLocation", "(", "model", ")", ";", "pos", ".", "add", "(", "ASSyntax", ".", "createStructure", "(", "\"pos\"", ",", "ASSyntax", ".", "createNumber", "(", "loc", ".", "x", ")", ",", "ASSyntax", ".", "createNumber", "(", "loc", ".", "y", ")", ")", ")", ";", "sizs", ".", "add", "(", "ASSyntax", ".", "createNumber", "(", "ClChosed", "[", "i", "]", ".", "d", ")", ")", ";", "}", "return", "un", ".", "unifies", "(", "args", "[", "4", "]", ",", "pos", ")", "&", "un", ".", "unifies", "(", "args", "[", "5", "]", ",", "sizs", ")", "&", "un", ".", "unifies", "(", "args", "[", "6", "]", ",", "new", "NumberTermImpl", "(", "ClChosed", ".", "length", ")", ")", ";", "}", "logger", ".", "warning", "(", "\"\"", ")", ";", "return", "null", ";", "}", "private", "contCluster", "nearCorralCluster", "(", "contCluster", "[", "]", "ClChosed", ")", "{", "contCluster", "cCl", "=", "ClChosed", "[", "0", "]", ";", "Location", "loc", "=", "cCl", ".", "v", ".", "getLocation", "(", "model", ")", ";", "int", "dist", "=", "loc", ".", "distance", "(", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "ClChosed", ".", "length", ";", "i", "++", ")", "{", "loc", "=", "ClChosed", "[", "i", "]", ".", "v", ".", "getLocation", "(", "model", ")", ";", "int", "newDist", "=", "loc", ".", "distance", "(", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ")", ";", "if", "(", "newDist", "<", "dist", ")", "{", "cCl", "=", "ClChosed", "[", "i", "]", ";", "}", "}", "return", "cCl", ";", "}", "private", "int", "getDistances", "(", "Location", "Cl", ",", "Location", "Gr", ")", "throws", "Exception", "{", "s", "=", "new", "Search", "(", "model", ",", "Cl", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "arch", ")", ";", "List", "<", "Nodo", ">", "path", "=", "Search", ".", "normalPath", "(", "s", ".", "search", "(", ")", ")", ";", "int", "ClToCo", "=", "path", ".", "size", "(", ")", ";", "s", "=", "new", "Search", "(", "model", ",", "Gr", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ",", "null", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "false", ",", "arch", ")", ";", "path", "=", "Search", ".", "normalPath", "(", "s", ".", "search", "(", ")", ")", ";", "int", "GrToCl", "=", "path", ".", "size", "(", ")", ";", "return", "ClToCo", "+", "GrToCl", ";", "}", "private", "contCluster", "[", "]", "getClusterWith", "(", "Location", "befCl", ",", "Location", "Gr", ")", "throws", "Exception", "{", "Vec", "[", "]", "Centers", "=", "ClModel", ".", "getCenters", "(", ")", ";", "int", "[", "]", "NumberOfCows", "=", "ClModel", ".", "getNumCows", "(", ")", ";", "int", "[", "]", "Radius", "=", "ClModel", ".", "getMaxDist", "(", ")", ";", "int", "clo", "=", "-", "1", ";", "if", "(", "befCl", "!=", "null", ")", "{", "int", "d", "=", "9", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "Centers", ".", "length", ";", "i", "++", ")", "{", "if", "(", "befCl", ".", "distanceChebyshev", "(", "Centers", "[", "i", "]", ".", "getLocation", "(", "model", ")", ")", "<", "d", ")", "{", "d", "=", "befCl", ".", "distanceChebyshev", "(", "Centers", "[", "i", "]", ".", "getLocation", "(", "model", ")", ")", ";", "clo", "=", "i", ";", "}", "}", "}", "contCluster", "[", "]", "cC", "=", "new", "contCluster", "[", "Centers", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "Centers", ".", "length", ";", "i", "++", ")", "{", "boolean", "clotemp", ";", "if", "(", "i", "==", "clo", ")", "{", "clotemp", "=", "true", ";", "}", "else", "{", "clotemp", "=", "false", ";", "}", "Location", "Cl", "=", "Centers", "[", "i", "]", ".", "getLocation", "(", "model", ")", ";", "int", "actdist", "=", "getDistances", "(", "Cl", ",", "Gr", ")", ";", "cC", "[", "i", "]", "=", "new", "contCluster", "(", "Centers", "[", "i", "]", ",", "actdist", ",", "NumberOfCows", "[", "i", "]", ",", "Radius", "[", "i", "]", ",", "clotemp", ")", ";", "}", "Arrays", ".", "sort", "(", "cC", ")", ";", "return", "cC", ";", "}", "private", "class", "contCluster", "implements", "Comparable", "<", "contCluster", ">", "{", "Vec", "v", ";", "int", "n", ";", "int", "r", ";", "int", "d", ";", "boolean", "clo", ";", "public", "contCluster", "(", "Vec", "v", ",", "int", "n", ",", "int", "r", ",", "int", "d", ",", "boolean", "clo", ")", "{", "this", ".", "v", "=", "v", ";", "this", ".", "n", "=", "n", ";", "this", ".", "r", "=", "r", ";", "this", ".", "d", "=", "d", ";", "this", ".", "clo", "=", "clo", ";", "}", "public", "int", "compareTo", "(", "contCluster", "arg0", ")", "{", "contCluster", "c", "=", "(", "contCluster", ")", "arg0", ";", "if", "(", "this", ".", "clo", ")", "return", "-", "1", ";", "if", "(", "c", ".", "clo", ")", "return", "1", ";", "if", "(", "this", ".", "n", ">", "n", "&&", "c", ".", "n", "<", "n", ")", "return", "-", "1", ";", "if", "(", "c", ".", "n", ">", "n", "&&", "this", ".", "n", "<", "n", ")", "return", "1", ";", "if", "(", "this", ".", "d", "<", "c", ".", "d", ")", "return", "-", "1", ";", "if", "(", "this", ".", "d", ">", "c", ".", "d", ")", "return", "1", ";", "if", "(", "this", ".", "r", "<", "c", ".", "r", ")", "return", "-", "1", ";", "if", "(", "c", ".", "r", "<", "this", ".", "r", ")", "return", "1", ";", "return", "0", ";", "}", "}", "}", "</s>" ]
9,135
[ "<s>", "package", "jia", ";", "import", "jason", ".", "asSemantics", ".", "DefaultInternalAction", ";", "import", "jason", ".", "asSemantics", ".", "TransitionSystem", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "arch", ".", "CowboyArch", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "set_target", "extends", "DefaultInternalAction", "{", "Location", "oldTarget", "=", "null", ";", "@", "Override", "public", "Object", "execute", "(", "TransitionSystem", "ts", ",", "Unifier", "un", ",", "Term", "[", "]", "terms", ")", "throws", "Exception", "{", "try", "{", "CowboyArch", "arch", "=", "(", "CowboyArch", ")", "ts", ".", "getUserAgArch", "(", ")", ";", "WorldModel", "model", "=", "arch", ".", "getModel", "(", ")", ";", "if", "(", "model", "==", "null", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ")", ";", "}", "else", "{", "if", "(", "oldTarget", "!=", "null", "&&", "model", ".", "inGrid", "(", "oldTarget", ")", ")", "{", "model", ".", "remove", "(", "WorldModel", ".", "TARGET", ",", "oldTarget", ")", ";", "}", "NumberTerm", "x", "=", "(", "NumberTerm", ")", "terms", "[", "0", "]", ";", "NumberTerm", "y", "=", "(", "NumberTerm", ")", "terms", "[", "1", "]", ";", "Location", "t", "=", "new", "Location", "(", "(", "int", ")", "x", ".", "solve", "(", ")", ",", "(", "int", ")", "y", ".", "solve", "(", ")", ")", ";", "if", "(", "model", ".", "inGrid", "(", "t", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "TARGET", ",", "t", ")", ";", "oldTarget", "=", "t", ";", "}", "}", "return", "true", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "ts", ".", "getLogger", "(", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", "+", "e", ",", "e", ")", ";", "}", "return", "false", ";", "}", "}", "</s>" ]
9,136
[ "<s>", "package", "test", ";", "import", "java", ".", "io", ".", "ByteArrayInputStream", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "OutputStream", ";", "import", "java", ".", "net", ".", "InetSocketAddress", ";", "import", "java", ".", "net", ".", "Socket", ";", "import", "java", ".", "text", ".", "SimpleDateFormat", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilderFactory", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "ParserConfigurationException", ";", "import", "javax", ".", "xml", ".", "transform", ".", "TransformerConfigurationException", ";", "import", "javax", ".", "xml", ".", "transform", ".", "TransformerException", ";", "import", "javax", ".", "xml", ".", "transform", ".", "TransformerFactory", ";", "import", "javax", ".", "xml", ".", "transform", ".", "dom", ".", "DOMSource", ";", "import", "javax", ".", "xml", ".", "transform", ".", "stream", ".", "StreamResult", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Document", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Element", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Node", ";", "import", "org", ".", "w3c", ".", "dom", ".", "NodeList", ";", "import", "org", ".", "xml", ".", "sax", ".", "SAXException", ";", "public", "abstract", "class", "AbstractAgent", "{", "@", "SuppressWarnings", "(", "\"serial\"", ")", "private", "class", "SocketClosedException", "extends", "Exception", "{", "}", "private", "int", "networkport", ";", "private", "String", "networkhost", ";", "private", "InetSocketAddress", "socketaddress", ";", "private", "Socket", "socket", ";", "private", "InputStream", "inputstream", ";", "private", "OutputStream", "outputstream", ";", "protected", "String", "username", ";", "private", "String", "password", ";", "protected", "DocumentBuilderFactory", "documentbuilderfactory", ";", "private", "TransformerFactory", "transformerfactory", ";", "protected", "static", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "\"agentLog.log\"", ")", ";", "public", "static", "String", "getDate", "(", ")", "{", "Date", "dt", "=", "new", "Date", "(", ")", ";", "SimpleDateFormat", "df", "=", "new", "SimpleDateFormat", "(", "\"\"", ")", ";", "return", "df", ".", "format", "(", "dt", ")", ";", "}", "public", "AbstractAgent", "(", ")", "{", "networkhost", "=", "\"localhost\"", ";", "networkport", "=", "0", ";", "socket", "=", "new", "Socket", "(", ")", ";", "documentbuilderfactory", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ";", "transformerfactory", "=", "TransformerFactory", ".", "newInstance", "(", ")", ";", "}", "public", "String", "getHost", "(", ")", "{", "return", "networkhost", ";", "}", "public", "void", "setHost", "(", "String", "host", ")", "{", "this", ".", "networkhost", "=", "host", ";", "}", "public", "int", "getPort", "(", ")", "{", "return", "networkport", ";", "}", "public", "void", "setPort", "(", "int", "port", ")", "{", "this", ".", "networkport", "=", "port", ";", "}", "public", "String", "getUsername", "(", ")", "{", "return", "username", ";", "}", "public", "void", "setUsername", "(", "String", "username", ")", "{", "this", ".", "username", "=", "username", ";", "}", "public", "String", "getPassword", "(", ")", "{", "return", "password", ";", "}", "public", "void", "setPassword", "(", "String", "password", ")", "{", "this", ".", "password", "=", "password", ";", "}", "public", "void", "start", "(", ")", "{", "new", "Thread", "(", ")", "{", "public", "void", "run", "(", ")", "{", "agentThread", "(", ")", ";", "}", "}", ".", "start", "(", ")", ";", "}", "public", "void", "sendAuthentication", "(", "String", "username", ",", "String", "password", ")", "throws", "IOException", "{", "try", "{", "Document", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "newDocument", "(", ")", ";", "Element", "root", "=", "doc", ".", "createElement", "(", "\"message\"", ")", ";", "root", ".", "setAttribute", "(", "\"type\"", ",", "\"auth-request\"", ")", ";", "doc", ".", "appendChild", "(", "root", ")", ";", "Element", "auth", "=", "doc", ".", "createElement", "(", "\"\"", ")", ";", "auth", ".", "setAttribute", "(", "\"username\"", ",", "username", ")", ";", "auth", ".", "setAttribute", "(", "\"password\"", ",", "password", ")", ";", "root", ".", "appendChild", "(", "auth", ")", ";", "this", ".", "sendDocument", "(", "doc", ")", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "boolean", "receiveAuthenticationResult", "(", ")", "throws", "IOException", "{", "try", "{", "Document", "doc", "=", "receiveDocument", "(", ")", ";", "Element", "root", "=", "doc", ".", "getDocumentElement", "(", ")", ";", "if", "(", "root", "==", "null", ")", "return", "false", ";", "if", "(", "!", "root", ".", "getAttribute", "(", "\"type\"", ")", ".", "equalsIgnoreCase", "(", "\"\"", ")", ")", "return", "false", ";", "NodeList", "nl", "=", "root", ".", "getChildNodes", "(", ")", ";", "Element", "authresult", "=", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "n", "=", "nl", ".", "item", "(", "i", ")", ";", "if", "(", "n", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "n", ".", "getNodeName", "(", ")", ".", "equalsIgnoreCase", "(", "\"\"", ")", ")", "{", "authresult", "=", "(", "Element", ")", "n", ";", "break", ";", "}", "}", "if", "(", "!", "authresult", ".", "getAttribute", "(", "\"result\"", ")", ".", "equalsIgnoreCase", "(", "\"ok\"", ")", ")", "return", "false", ";", "}", "catch", "(", "SAXException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "false", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "false", ";", "}", "catch", "(", "SocketClosedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}", "public", "boolean", "doAuthentication", "(", "String", "username", ",", "String", "password", ")", "throws", "IOException", "{", "sendAuthentication", "(", "username", ",", "password", ")", ";", "return", "receiveAuthenticationResult", "(", ")", ";", "}", "public", "byte", "[", "]", "receivePacket", "(", ")", "throws", "IOException", ",", "SocketClosedException", "{", "ByteArrayOutputStream", "buffer", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "int", "read", "=", "inputstream", ".", "read", "(", ")", ";", "while", "(", "read", "!=", "0", ")", "{", "if", "(", "read", "==", "-", "1", ")", "{", "throw", "new", "SocketClosedException", "(", ")", ";", "}", "buffer", ".", "write", "(", "read", ")", ";", "read", "=", "inputstream", ".", "read", "(", ")", ";", "}", "String", "s", "=", "\"\"", "+", "this", ".", "username", "+", "\"n\"", "+", "buffer", ".", "toString", "(", ")", ";", "synchronized", "(", "logger", ")", "{", "logger", ".", "log", "(", "Level", ".", "ALL", ",", "s", ")", ";", "}", "return", "buffer", ".", "toByteArray", "(", ")", ";", "}", "public", "Document", "receiveDocument", "(", ")", "throws", "SAXException", ",", "IOException", ",", "ParserConfigurationException", ",", "SocketClosedException", "{", "byte", "[", "]", "raw", "=", "receivePacket", "(", ")", ";", "Document", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "parse", "(", "new", "ByteArrayInputStream", "(", "raw", ")", ")", ";", "return", "doc", ";", "}", "public", "void", "agentThread", "(", ")", "{", "try", "{", "socketaddress", "=", "new", "InetSocketAddress", "(", "networkhost", ",", "networkport", ")", ";", "socket", ".", "connect", "(", "socketaddress", ")", ";", "inputstream", "=", "socket", ".", "getInputStream", "(", ")", ";", "outputstream", "=", "socket", ".", "getOutputStream", "(", ")", ";", "boolean", "auth", "=", "doAuthentication", "(", "username", ",", "password", ")", ";", "if", "(", "!", "auth", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "return", ";", "}", "processLogIn", "(", ")", ";", "while", "(", "true", ")", "{", "Document", "doc", "=", "null", ";", "try", "{", "doc", "=", "receiveDocument", "(", ")", ";", "}", "catch", "(", "SAXException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "Element", "el_root", "=", "doc", ".", "getDocumentElement", "(", ")", ";", "if", "(", "el_root", "==", "null", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "continue", ";", "}", "if", "(", "el_root", ".", "getNodeName", "(", ")", ".", "equals", "(", "\"message\"", ")", ")", "{", "if", "(", "!", "processMessage", "(", "el_root", ")", ")", "break", ";", "}", "else", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "}", "}", "}", "catch", "(", "IOException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"IOException\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "return", ";", "}", "catch", "(", "SocketClosedException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "}", "}", "@", "SuppressWarnings", "(", "\"\"", ")", "public", "boolean", "processMessage", "(", "Element", "el_message", ")", "{", "String", "type", "=", "el_message", ".", "getAttribute", "(", "\"type\"", ")", ";", "if", "(", "type", ".", "equals", "(", "\"\"", ")", "||", "type", ".", "equals", "(", "\"sim-start\"", ")", "||", "type", ".", "equals", "(", "\"sim-end\"", ")", ")", "{", "Element", "el_perception", "=", "null", ";", "NodeList", "nl", "=", "el_message", ".", "getChildNodes", "(", ")", ";", "String", "infoelementname", "=", "\"perception\"", ";", "if", "(", "type", ".", "equals", "(", "\"\"", ")", ")", "{", "infoelementname", "=", "\"perception\"", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-start\"", ")", ")", "{", "infoelementname", "=", "\"simulation\"", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-end\"", ")", ")", "{", "infoelementname", "=", "\"sim-result\"", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "n", "=", "nl", ".", "item", "(", "i", ")", ";", "if", "(", "n", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "n", ".", "getNodeName", "(", ")", ".", "equalsIgnoreCase", "(", "infoelementname", ")", ")", "{", "if", "(", "el_perception", "==", "null", ")", "el_perception", "=", "(", "Element", ")", "n", ";", "else", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "return", "true", ";", "}", "}", "}", "Document", "doc", "=", "null", ";", "try", "{", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "newDocument", "(", ")", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "Element", "el_response", "=", "doc", ".", "createElement", "(", "\"message\"", ")", ";", "doc", ".", "appendChild", "(", "el_response", ")", ";", "Element", "el_action", "=", "doc", ".", "createElement", "(", "\"action\"", ")", ";", "el_response", ".", "setAttribute", "(", "\"type\"", ",", "\"action\"", ")", ";", "el_response", ".", "appendChild", "(", "el_action", ")", ";", "long", "currenttime", "=", "0", ";", "try", "{", "currenttime", "=", "Long", ".", "parseLong", "(", "el_message", ".", "getAttribute", "(", "\"timestamp\"", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "return", "true", ";", "}", "long", "deadline", "=", "0", ";", "if", "(", "type", ".", "equals", "(", "\"\"", ")", ")", "{", "try", "{", "deadline", "=", "Long", ".", "parseLong", "(", "el_perception", ".", "getAttribute", "(", "\"deadline\"", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "return", "true", ";", "}", "processRequestAction", "(", "el_perception", ",", "el_action", ",", "currenttime", ",", "deadline", ")", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-start\"", ")", ")", "{", "processSimulationStart", "(", "el_perception", ",", "currenttime", ")", ";", "}", "else", "if", "(", "type", ".", "equals", "(", "\"sim-end\"", ")", ")", "{", "processSimulationEnd", "(", "el_perception", ",", "currenttime", ")", ";", "}", "el_action", ".", "setAttribute", "(", "\"id\"", ",", "el_perception", ".", "getAttribute", "(", "\"id\"", ")", ")", ";", "try", "{", "if", "(", "type", ".", "equals", "(", "\"\"", ")", ")", "sendDocument", "(", "doc", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "}", "else", "if", "(", "type", ".", "equals", "(", "\"pong\"", ")", ")", "{", "NodeList", "nl", "=", "el_message", ".", "getChildNodes", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nl", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Node", "n", "=", "nl", ".", "item", "(", "i", ")", ";", "if", "(", "n", ".", "getNodeType", "(", ")", "==", "Element", ".", "ELEMENT_NODE", "&&", "n", ".", "getNodeName", "(", ")", ".", "equalsIgnoreCase", "(", "\"payload\"", ")", ")", "{", "processPong", "(", "(", "(", "Element", ")", "n", ")", ".", "getAttribute", "(", "\"value\"", ")", ")", ";", "return", "true", ";", "}", "}", "}", "return", "true", ";", "}", "public", "void", "processRequestAction", "(", "Element", "perception", ",", "Element", "target", ",", "long", "currenttime", ",", "long", "deadline", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "}", "public", "void", "processSimulationEnd", "(", "Element", "perception", ",", "long", "currenttime", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "}", "public", "void", "processSimulationStart", "(", "Element", "perception", ",", "long", "currenttime", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "}", "public", "void", "processPong", "(", "String", "pong", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", "+", "pong", "+", "\"\"", ")", ";", "}", "public", "void", "processLogIn", "(", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "}", "public", "void", "sendDocument", "(", "Document", "doc", ")", "throws", "IOException", "{", "try", "{", "transformerfactory", ".", "newTransformer", "(", ")", ".", "transform", "(", "new", "DOMSource", "(", "doc", ")", ",", "new", "StreamResult", "(", "outputstream", ")", ")", ";", "ByteArrayOutputStream", "temp", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "transformerfactory", ".", "newTransformer", "(", ")", ".", "transform", "(", "new", "DOMSource", "(", "doc", ")", ",", "new", "StreamResult", "(", "temp", ")", ")", ";", "String", "s", "=", "\"\"", "+", "temp", ".", "toString", "(", ")", ";", "logger", ".", "log", "(", "Level", ".", "ALL", ",", "s", ")", ";", "outputstream", ".", "write", "(", "0", ")", ";", "outputstream", ".", "flush", "(", ")", ";", "}", "catch", "(", "TransformerConfigurationException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "catch", "(", "TransformerException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "}", "public", "void", "sendPing", "(", "String", "ping", ")", "throws", "IOException", "{", "Document", "doc", "=", "null", ";", "try", "{", "doc", "=", "documentbuilderfactory", ".", "newDocumentBuilder", "(", ")", ".", "newDocument", "(", ")", ";", "}", "catch", "(", "ParserConfigurationException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "Element", "root", "=", "doc", ".", "createElement", "(", "\"message\"", ")", ";", "doc", ".", "appendChild", "(", "root", ")", ";", "root", ".", "setAttribute", "(", "\"type\"", ",", "\"ping\"", ")", ";", "Element", "payload", "=", "doc", ".", "createElement", "(", "\"payload\"", ")", ";", "payload", ".", "setAttribute", "(", "\"value\"", ",", "ping", ")", ";", "root", ".", "appendChild", "(", "payload", ")", ";", "sendDocument", "(", "doc", ")", ";", "}", "}", "</s>" ]
9,137
[ "<s>", "package", "test", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Element", ";", "public", "class", "DemoAgent", "extends", "AbstractAgent", "{", "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "DemoAgent", "agent", "=", "new", "DemoAgent", "(", ")", ";", "agent", ".", "setPort", "(", "12300", ")", ";", "agent", ".", "setHost", "(", "\"localhost\"", ")", ";", "agent", ".", "setUsername", "(", "args", "[", "0", "]", ")", ";", "agent", ".", "setPassword", "(", "args", "[", "1", "]", ")", ";", "agent", ".", "start", "(", ")", ";", "}", "public", "void", "processLogIn", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"Login", "Ok\"", ")", ";", "new", "Thread", "(", ")", "{", "public", "void", "run", "(", ")", "{", "int", "i", "=", "0", ";", "while", "(", "true", ")", "{", "try", "{", "sleep", "(", "1000", ")", ";", "System", ".", "out", ".", "println", "(", "\"send", "ping", "\"", "+", "i", ")", ";", "sendPing", "(", "\"test\"", "+", "i", ")", ";", "i", "++", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", ";", "}", ".", "start", "(", ")", ";", "}", "public", "void", "processPong", "(", "String", "pong", ")", "{", "System", ".", "out", ".", "println", "(", "\"Rec", "Pong", "\"", "+", "pong", ")", ";", "}", "public", "void", "processSimulationEnd", "(", "Element", "perception", ",", "long", "currenttime", ")", "{", "}", "public", "void", "processSimulationStart", "(", "Element", "perception", ",", "long", "currenttime", ")", "{", "System", ".", "out", ".", "println", "(", "\"Start!\"", ")", ";", "}", "public", "void", "processRequestAction", "(", "Element", "perception", ",", "Element", "target", ",", "long", "currenttime", ",", "long", "deadline", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", ")", ";", "}", "}", "</s>" ]
9,138
[ "<s>", "package", "test", ";", "import", "static", "org", ".", "junit", ".", "Assert", ".", "assertEquals", ";", "import", "static", "org", ".", "junit", ".", "Assert", ".", "assertTrue", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "List", ";", "import", "jia", ".", "Search", ";", "import", "jia", ".", "Vec", ";", "import", "jia", ".", "cluster", ";", "import", "jia", ".", "herd_position", ";", "import", "jia", ".", "other_side_fence", ";", "import", "jia", ".", "scouter_pos", ";", "import", "jia", ".", "herd_position", ".", "Formation", ";", "import", "org", ".", "junit", ".", "Before", ";", "import", "org", ".", "junit", ".", "Ignore", ";", "import", "org", ".", "junit", ".", "Test", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "busca", ".", "Nodo", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "TestBasicHerding", "{", "Vec", "cowboy", ";", "LocalWorldModel", "model", ";", "@", "Before", "public", "void", "scenario", "(", ")", "{", "model", "=", "new", "LocalWorldModel", "(", "50", ",", "50", ",", "WorldModel", ".", "agsByTeam", ",", "null", ")", ";", "model", ".", "setCorral", "(", "new", "Location", "(", "0", ",", "49", ")", ",", "new", "Location", "(", "2", ",", "49", ")", ")", ";", "model", ".", "wall", "(", "7", ",", "44", ",", "7", ",", "49", ")", ";", "}", "public", "void", "scenario1", "(", ")", "{", "cowboy", "=", "new", "Vec", "(", "3", ",", "5", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "AGENT", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "addCowsToModel", "(", "new", "Vec", "(", "6", ",", "7", ")", ",", "new", "Vec", "(", "5", ",", "30", ")", ",", "new", "Vec", "(", "4", ",", "8", ")", ",", "new", "Vec", "(", "5", ",", "10", ")", ",", "new", "Vec", "(", "2", ",", "0", ")", ")", ";", "}", "public", "void", "scenario2", "(", ")", "{", "cowboy", "=", "new", "Vec", "(", "11", ",", "3", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "AGENT", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "addCowsToModel", "(", "new", "Vec", "(", "8", ",", "0", ")", ",", "new", "Vec", "(", "9", ",", "0", ")", ",", "new", "Vec", "(", "10", ",", "0", ")", ",", "new", "Vec", "(", "8", ",", "1", ")", ",", "new", "Vec", "(", "9", ",", "1", ")", ",", "new", "Vec", "(", "10", ",", "1", ")", ",", "new", "Vec", "(", "8", ",", "2", ")", ",", "new", "Vec", "(", "9", ",", "2", ")", ",", "new", "Vec", "(", "10", ",", "2", ")", ")", ";", "}", "public", "void", "scenario3", "(", ")", "{", "model", "=", "new", "LocalWorldModel", "(", "50", ",", "19", ",", "WorldModel", ".", "agsByTeam", ",", "null", ")", ";", "model", ".", "setCorral", "(", "new", "Location", "(", "8", ",", "0", ")", ",", "new", "Location", "(", "12", ",", "2", ")", ")", ";", "model", ".", "wall", "(", "7", ",", "0", ",", "7", ",", "2", ")", ";", "cowboy", "=", "new", "Vec", "(", "10", ",", "12", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "AGENT", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "addCowsToModel", "(", "new", "Vec", "(", "1", ",", "16", ")", ",", "new", "Vec", "(", "2", ",", "14", ")", ",", "new", "Vec", "(", "3", ",", "13", ")", ",", "new", "Vec", "(", "5", ",", "14", ")", ",", "new", "Vec", "(", "6", ",", "12", ")", ",", "new", "Vec", "(", "6", ",", "13", ")", ",", "new", "Vec", "(", "20", ",", "2", ")", ",", "new", "Vec", "(", "20", ",", "3", ")", ",", "new", "Vec", "(", "20", ",", "4", ")", ")", ";", "}", "public", "void", "scenario4", "(", ")", "{", "addFenceToModel", "(", "new", "Vec", "(", "18", ",", "0", ")", ",", "new", "Vec", "(", "18", ",", "1", ")", ",", "new", "Vec", "(", "18", ",", "2", ")", ",", "new", "Vec", "(", "18", ",", "3", ")", ",", "new", "Vec", "(", "18", ",", "4", ")", ",", "new", "Vec", "(", "18", ",", "5", ")", ",", "new", "Vec", "(", "18", ",", "6", ")", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "SWITCH", ",", "18", ",", "42", ")", ";", "}", "@", "Test", "public", "void", "bigCluster", "(", ")", "throws", "Exception", "{", "for", "(", "int", "x", "=", "10", ";", "x", "<", "30", ";", "x", "++", ")", "{", "for", "(", "int", "y", "=", "5", ";", "y", "<", "20", ";", "y", "++", ")", "{", "addCowsToModel", "(", "new", "Vec", "(", "model", ",", "x", ",", "y", ")", ")", ";", "}", "}", "List", "<", "Location", ">", "cowsl", "=", "cluster", ".", "getCluster", "(", "model", ",", "WorldModel", ".", "cowPerceptionRatio", ",", "null", ")", ";", "assertEquals", "(", "cluster", ".", "MAXCLUSTERSIZE", ",", "cowsl", ".", "size", "(", ")", ")", ";", "}", "private", "void", "addCowsToModel", "(", "Vec", "...", "cows", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "cows", ".", "length", ";", "i", "++", ")", "{", "Location", "l", "=", "cows", "[", "i", "]", ".", "getLocation", "(", "model", ")", ";", "model", ".", "addKnownCow", "(", "l", ".", "x", ",", "l", ".", "y", ")", ";", "}", "}", "private", "void", "addFenceToModel", "(", "Vec", "...", "fences", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "fences", ".", "length", ";", "i", "++", ")", "{", "Location", "l", "=", "fences", "[", "i", "]", ".", "getLocation", "(", "model", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "l", ".", "x", ",", "l", ".", "y", ")", ";", "}", "}", "@", "Test", "public", "void", "testVec", "(", ")", "{", "scenario1", "(", ")", ";", "assertEquals", "(", "new", "Location", "(", "3", ",", "44", ")", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "assertEquals", "(", "new", "Location", "(", "1", ",", "49", ")", ",", "model", ".", "getCorral", "(", ")", ".", "center", "(", ")", ")", ";", "assertEquals", "(", "new", "Vec", "(", "3", ",", "2", ")", ",", "new", "Vec", "(", "6", ",", "7", ")", ".", "sub", "(", "cowboy", ")", ")", ";", "Vec", "v", "=", "new", "Vec", "(", "3", ",", "2", ")", ";", "assertEquals", "(", "v", ",", "v", ".", "newAngle", "(", "v", ".", "angle", "(", ")", ")", ")", ";", "}", "@", "Test", "public", "void", "testOtherSideFence", "(", ")", "throws", "Exception", "{", "scenario4", "(", ")", ";", "assertTrue", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "FENCE", ",", "new", "Vec", "(", "18", ",", "2", ")", ".", "getLocation", "(", "model", ")", ")", ")", ";", "Vec", "start", "=", "new", "Vec", "(", "model", ",", "15", ",", "45", ")", ";", "Vec", "fence", "=", "new", "Vec", "(", "model", ",", "18", ",", "45", ")", ";", "Vec", "target", "=", "new", "other_side_fence", "(", ")", ".", "computesOtherSide", "(", "model", ",", "start", ",", "fence", ")", ";", "assertEquals", "(", "new", "Location", "(", "21", ",", "45", ")", ",", "target", ".", "getLocation", "(", "model", ")", ")", ";", "start", "=", "new", "Vec", "(", "model", ",", "10", ",", "42", ")", ";", "fence", "=", "new", "Vec", "(", "model", ",", "18", ",", "45", ")", ";", "target", "=", "new", "other_side_fence", "(", ")", ".", "computesOtherSide", "(", "model", ",", "start", ",", "fence", ")", ";", "assertEquals", "(", "new", "Location", "(", "26", ",", "48", ")", ",", "target", ".", "getLocation", "(", "model", ")", ")", ";", "start", "=", "new", "Vec", "(", "model", ",", "17", ",", "44", ")", ";", "fence", "=", "new", "Vec", "(", "model", ",", "18", ",", "45", ")", ";", "target", "=", "new", "other_side_fence", "(", ")", ".", "computesOtherSide", "(", "model", ",", "start", ",", "fence", ")", ";", "assertEquals", "(", "new", "Location", "(", "19", ",", "46", ")", ",", "target", ".", "getLocation", "(", "model", ")", ")", ";", "}", "@", "Test", "public", "void", "testVecSort", "(", ")", "{", "scenario1", "(", ")", ";", "List", "<", "Vec", ">", "cowsl", "=", "new", "ArrayList", "<", "Vec", ">", "(", "model", ".", "getKnownCows", "(", ")", ")", ";", "Collections", ".", "sort", "(", "cowsl", ")", ";", "assertEquals", "(", "new", "Vec", "(", "2", ",", "0", ")", ",", "cowsl", ".", "get", "(", "0", ")", ")", ";", "assertEquals", "(", "new", "Vec", "(", "4", ",", "8", ")", ",", "cowsl", ".", "get", "(", "1", ")", ")", ";", "assertEquals", "(", "new", "Vec", "(", "6", ",", "7", ")", ",", "cowsl", ".", "get", "(", "2", ")", ")", ";", "assertEquals", "(", "new", "Vec", "(", "5", ",", "10", ")", ",", "cowsl", ".", "get", "(", "3", ")", ")", ";", "assertEquals", "(", "new", "Vec", "(", "5", ",", "30", ")", ",", "cowsl", ".", "get", "(", "4", ")", ")", ";", "}", "@", "Test", "public", "void", "testCowsRepMat", "(", ")", "throws", "Exception", "{", "scenario1", "(", ")", ";", "assertEquals", "(", "2", ",", "model", ".", "getCowsRep", "(", "5", ",", "38", ")", ")", ";", "assertEquals", "(", "1", ",", "model", ".", "getCowsRep", "(", "5", ",", "37", ")", ")", ";", "assertEquals", "(", "0", ",", "model", ".", "getCowsRep", "(", "5", ",", "36", ")", ")", ";", "assertEquals", "(", "5", ",", "model", ".", "getCowsRep", "(", "5", ",", "40", ")", ")", ";", "}", "@", "Test", "public", "void", "testAgsRepMat", "(", ")", "throws", "Exception", "{", "scenario1", "(", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMY", ",", "4", ",", "44", ")", ";", "model", ".", "remove", "(", "WorldModel", ".", "ENEMY", ",", "4", ",", "44", ")", ";", "assertEquals", "(", "2", ",", "model", ".", "getObsRep", "(", "6", ",", "44", ")", ")", ";", "assertEquals", "(", "1", ",", "model", ".", "getObsRep", "(", "7", ",", "43", ")", ")", ";", "assertEquals", "(", "0", ",", "model", ".", "getObsRep", "(", "5", ",", "44", ")", ")", ";", "}", "@", "Test", "public", "void", "testAStar1", "(", ")", "throws", "Exception", "{", "scenario1", "(", ")", ";", "Search", "s", "=", "new", "Search", "(", "model", ",", "cowboy", ".", "getLocation", "(", "model", ")", ",", "new", "Location", "(", "8", ",", "37", ")", ",", "null", ",", "true", ",", "true", ",", "true", ",", "false", ",", "false", ",", "false", ",", "null", ")", ";", "Nodo", "path", "=", "s", ".", "search", "(", ")", ";", "assertEquals", "(", "13", ",", "Search", ".", "normalPath", "(", "path", ")", ".", "size", "(", ")", ")", ";", "}", "@", "Test", "public", "void", "testAStar2", "(", ")", "throws", "Exception", "{", "scenario1", "(", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "0", ",", "40", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "1", ",", "40", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "2", ",", "40", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "3", ",", "40", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "CLOSED_FENCE", ",", "4", ",", "40", ")", ";", "Search", "s", "=", "new", "Search", "(", "model", ",", "cowboy", ".", "getLocation", "(", "model", ")", ",", "new", "Location", "(", "8", ",", "37", ")", ",", "null", ",", "true", ",", "true", ",", "true", ",", "false", ",", "false", ",", "true", ",", "null", ")", ";", "Nodo", "path", "=", "s", ".", "search", "(", ")", ";", "assertEquals", "(", "11", ",", "Search", ".", "normalPath", "(", "path", ")", ".", "size", "(", ")", ")", ";", "s", "=", "new", "Search", "(", "model", ",", "cowboy", ".", "getLocation", "(", "model", ")", ",", "new", "Location", "(", "8", ",", "37", ")", ",", "null", ",", "true", ",", "true", ",", "true", ",", "false", ",", "false", ",", "false", ",", "null", ")", ";", "path", "=", "s", ".", "search", "(", ")", ";", "assertEquals", "(", "11", ",", "Search", ".", "normalPath", "(", "path", ")", ".", "size", "(", ")", ")", ";", "}", "@", "Test", "public", "void", "testAStarPathInEnemyCorral", "(", ")", "throws", "Exception", "{", "scenario3", "(", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "10", ",", "7", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "11", ",", "7", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "12", ",", "7", ")", ";", "Search", "s", "=", "new", "Search", "(", "model", ",", "new", "Location", "(", "12", ",", "12", ")", ",", "new", "Location", "(", "10", ",", "1", ")", ",", "null", ",", "true", ",", "false", ",", "true", ",", "false", ",", "true", ",", "false", ",", "null", ")", ";", "Nodo", "path", "=", "s", ".", "search", "(", ")", ";", "assertTrue", "(", "Search", ".", "normalPath", "(", "path", ")", ".", "size", "(", ")", ">", "10", ")", ";", "}", "@", "Test", "public", "void", "moveCows2", "(", ")", "throws", "Exception", "{", "scenario1", "(", ")", ";", "List", "<", "Location", ">", "clusterLocs", "=", "cluster", ".", "getCluster", "(", "model", ",", "WorldModel", ".", "cowPerceptionRatio", ",", "null", ")", ";", "List", "<", "Vec", ">", "cowsl", "=", "cluster", ".", "location2vec", "(", "model", ",", "clusterLocs", ")", ";", "assertEquals", "(", "3", ",", "cowsl", ".", "size", "(", ")", ")", ";", "Vec", "mean", "=", "Vec", ".", "mean", "(", "cowsl", ")", ";", "assertEquals", "(", "new", "Vec", "(", "5", ",", "8", ")", ",", "mean", ")", ";", "int", "stepsFromCenter", "=", "(", "int", ")", "Math", ".", "round", "(", "Vec", ".", "max", "(", "cowsl", ")", ".", "sub", "(", "mean", ")", ".", "magnitude", "(", ")", ")", "+", "1", ";", "assertEquals", "(", "3", ",", "stepsFromCenter", ")", ";", "herd_position", "hp", "=", "new", "herd_position", "(", ")", ";", "hp", ".", "setModel", "(", "model", ")", ";", "Location", "byIA", "=", "hp", ".", "getAgTarget", "(", "clusterLocs", ",", "Formation", ".", "one", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "assertEquals", "(", "new", "Location", "(", "6", ",", "38", ")", ",", "byIA", ")", ";", "assertEquals", "(", "\"\"", ",", "hp", ".", "formationPlaces", "(", "clusterLocs", ",", "Formation", ".", "five", ")", ".", "toString", "(", ")", ")", ";", "byIA", "=", "hp", ".", "getAgTarget", "(", "clusterLocs", ",", "Formation", ".", "six", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "assertEquals", "(", "new", "Location", "(", "8", ",", "39", ")", ",", "byIA", ")", ";", "assertEquals", "(", "\"\"", ",", "hp", ".", "formationPlaces", "(", "clusterLocs", ",", "Formation", ".", "six", ")", ".", "toString", "(", ")", ")", ";", "}", "@", "Test", "public", "void", "moveCows3", "(", ")", "throws", "Exception", "{", "scenario2", "(", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMY", ",", "11", ",", "48", ")", ";", "List", "<", "Location", ">", "clusterLocs", "=", "cluster", ".", "getCluster", "(", "model", ",", "WorldModel", ".", "cowPerceptionRatio", ",", "null", ")", ";", "List", "<", "Vec", ">", "cowsl", "=", "cluster", ".", "location2vec", "(", "model", ",", "clusterLocs", ")", ";", "assertEquals", "(", "9", ",", "cowsl", ".", "size", "(", ")", ")", ";", "herd_position", "hp", "=", "new", "herd_position", "(", ")", ";", "hp", ".", "setModel", "(", "model", ")", ";", "Location", "byIA", "=", "hp", ".", "getAgTarget", "(", "clusterLocs", ",", "Formation", ".", "one", ",", "cowboy", ".", "getLocation", "(", "model", ")", ")", ";", "assertEquals", "(", "new", "Location", "(", "11", ",", "49", ")", ",", "byIA", ")", ";", "List", "<", "Location", ">", "form", "=", "hp", ".", "formationPlaces", "(", "clusterLocs", ",", "Formation", ".", "four", ")", ";", "assertTrue", "(", "form", ".", "contains", "(", "new", "Location", "(", "11", ",", "49", ")", ")", ")", ";", "assertTrue", "(", "form", ".", "contains", "(", "new", "Location", "(", "6", ",", "49", ")", ")", ")", ";", "}", "@", "Test", "@", "Ignore", "public", "void", "formationSc3", "(", ")", "throws", "Exception", "{", "scenario3", "(", ")", ";", "List", "<", "Location", ">", "clusterLocs", "=", "cluster", ".", "getCluster", "(", "model", ",", "WorldModel", ".", "cowPerceptionRatio", ",", "null", ")", ";", "assertEquals", "(", "6", ",", "clusterLocs", ".", "size", "(", ")", ")", ";", "herd_position", "hp", "=", "new", "herd_position", "(", ")", ";", "hp", ".", "setModel", "(", "model", ")", ";", "List", "<", "Location", ">", "form", "=", "hp", ".", "formationPlaces", "(", "clusterLocs", ",", "Formation", ".", "four", ")", ";", "assertTrue", "(", "form", ".", "contains", "(", "new", "Location", "(", "0", ",", "4", ")", ")", "||", "form", ".", "contains", "(", "new", "Location", "(", "0", ",", "3", ")", ")", ")", ";", "assertTrue", "(", "form", ".", "contains", "(", "new", "Location", "(", "0", ",", "8", ")", ")", ")", ";", "assertTrue", "(", "form", ".", "contains", "(", "new", "Location", "(", "0", ",", "1", ")", ")", "||", "form", ".", "contains", "(", "new", "Location", "(", "0", ",", "0", ")", ")", ")", ";", "assertTrue", "(", "form", ".", "contains", "(", "new", "Location", "(", "4", ",", "11", ")", ")", ")", ";", "}", "@", "Test", "public", "void", "scouterPos", "(", ")", "throws", "Exception", "{", "scenario1", "(", ")", ";", "Location", "byIA", "=", "new", "scouter_pos", "(", ")", ".", "getScouterTarget", "(", "model", ",", "new", "Location", "(", "2", ",", "46", ")", ",", "new", "Location", "(", "5", ",", "44", ")", ")", ";", "assertEquals", "(", "new", "Location", "(", "6", ",", "46", ")", ",", "byIA", ")", ";", "byIA", "=", "new", "scouter_pos", "(", ")", ".", "getScouterTarget", "(", "model", ",", "new", "Location", "(", "9", ",", "46", ")", ",", "new", "Location", "(", "9", ",", "42", ")", ")", ";", "assertEquals", "(", "new", "Location", "(", "22", ",", "42", ")", ",", "byIA", ")", ";", "}", "}", "</s>" ]
9,139
[ "<s>", "package", "test", ";", "import", "static", "org", ".", "junit", ".", "Assert", ".", "assertFalse", ";", "import", "static", "org", ".", "junit", ".", "Assert", ".", "assertTrue", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "org", ".", "junit", ".", "Before", ";", "import", "org", ".", "junit", ".", "Test", ";", "import", "arch", ".", "LocalWorldModel", ";", "import", "env", ".", "WorldModel", ";", "public", "class", "TestWorldModel", "{", "LocalWorldModel", "model", ";", "@", "Before", "public", "void", "scenario", "(", ")", "{", "model", "=", "new", "LocalWorldModel", "(", "50", ",", "50", ",", "WorldModel", ".", "agsByTeam", ",", "null", ")", ";", "}", "@", "Test", "public", "void", "testIsFree", "(", ")", "{", "Location", "l", "=", "new", "Location", "(", "10", ",", "10", ")", ";", "assertTrue", "(", "model", ".", "isFree", "(", "l", ")", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", ";", "assertFalse", "(", "model", ".", "isFree", "(", "l", ")", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "l", ")", ";", "assertFalse", "(", "model", ".", "isFree", "(", "l", ")", ")", ";", "l", "=", "new", "Location", "(", "10", ",", "11", ")", ";", "assertTrue", "(", "model", ".", "isFree", "(", "l", ")", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "l", ")", ";", "assertTrue", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "l", ")", ")", ";", "assertFalse", "(", "model", ".", "isFree", "(", "l", ")", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", ";", "assertFalse", "(", "model", ".", "isFree", "(", "l", ")", ")", ";", "assertTrue", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "l", ")", ")", ";", "assertTrue", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "ENEMYCORRAL", ",", "l", ")", ")", ";", "}", "}", "</s>" ]
9,140
[ "<s>", "package", "test", ";", "import", "static", "org", ".", "junit", ".", "Assert", ".", "assertEquals", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "org", ".", "junit", ".", "Test", ";", "import", "agent", ".", "UniqueBelsBB", ";", "public", "class", "TestUniqueBB", "{", "@", "Test", "public", "void", "removeOldBB", "(", ")", "{", "UniqueBelsBB", "bb", "=", "new", "UniqueBelsBB", "(", ")", ";", "bb", ".", "add", "(", "Literal", ".", "parseLiteral", "(", "\"\"", ")", ")", ";", "bb", ".", "add", "(", "Literal", ".", "parseLiteral", "(", "\"\"", ")", ")", ";", "bb", ".", "add", "(", "Literal", ".", "parseLiteral", "(", "\"cow(3,1,1)\"", ")", ")", ";", "bb", ".", "remove_old_bels", "(", "Literal", ".", "parseLiteral", "(", "\"cow(1,1,1)\"", ")", ",", "\"step\"", ",", "4", ",", "11", ")", ";", "assertEquals", "(", "2", ",", "bb", ".", "size", "(", ")", ")", ";", "bb", ".", "remove_old_bels", "(", "Literal", ".", "parseLiteral", "(", "\"cow(1,1,1)\"", ")", ",", "\"step\"", ",", "4", ",", "12", ")", ";", "bb", ".", "remove_old_bels", "(", "Literal", ".", "parseLiteral", "(", "\"cow(1,1,1)\"", ")", ",", "\"step\"", ",", "4", ",", "15", ")", ";", "assertEquals", "(", "1", ",", "bb", ".", "size", "(", ")", ")", ";", "}", "}", "</s>" ]
9,141
[ "<s>", "package", "test", ";", "import", "jason", ".", "util", ".", "asl2html", ";", "import", "java", ".", "awt", ".", "BorderLayout", ";", "import", "java", ".", "awt", ".", "Dimension", ";", "import", "java", ".", "awt", ".", "FlowLayout", ";", "import", "java", ".", "awt", ".", "Toolkit", ";", "import", "java", ".", "awt", ".", "event", ".", "ActionEvent", ";", "import", "java", ".", "awt", ".", "event", ".", "ActionListener", ";", "import", "java", ".", "io", ".", "File", ";", "import", "javax", ".", "swing", ".", "BorderFactory", ";", "import", "javax", ".", "swing", ".", "JButton", ";", "import", "javax", ".", "swing", ".", "JFrame", ";", "import", "javax", ".", "swing", ".", "JPanel", ";", "import", "javax", ".", "swing", ".", "JScrollPane", ";", "import", "javax", ".", "swing", ".", "JSlider", ";", "import", "javax", ".", "swing", ".", "JTextPane", ";", "import", "javax", ".", "swing", ".", "SwingUtilities", ";", "import", "javax", ".", "swing", ".", "border", ".", "TitledBorder", ";", "import", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", ";", "import", "javax", ".", "swing", ".", "event", ".", "ChangeListener", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilder", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilderFactory", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "ParserConfigurationException", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Document", ";", "public", "class", "MindView", "{", "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "new", "MindView", "(", "Integer", ".", "parseInt", "(", "args", "[", "0", "]", ")", ")", ";", "}", "private", "int", "step", "=", "1", ";", "private", "asl2html", "agTransformerHtml", "=", "new", "asl2html", "(", "\"\"", ")", ";", "private", "DocumentBuilder", "builder", ";", "public", "MindView", "(", "int", "step", ")", "throws", "ParserConfigurationException", "{", "this", ".", "step", "=", "step", ";", "builder", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ".", "newDocumentBuilder", "(", ")", ";", "initComponents", "(", ")", ";", "show", "(", ")", ";", "}", "JTextPane", "jTA", "=", "null", ";", "JFrame", "frame", ";", "JSlider", "jHistory", "=", "null", ";", "void", "initComponents", "(", ")", "{", "frame", "=", "new", "JFrame", "(", ")", ";", "jTA", "=", "new", "JTextPane", "(", ")", ";", "jTA", ".", "setEditable", "(", "false", ")", ";", "jTA", ".", "setContentType", "(", "\"text/html\"", ")", ";", "jTA", ".", "setAutoscrolls", "(", "false", ")", ";", "JPanel", "spTA", "=", "new", "JPanel", "(", "new", "BorderLayout", "(", ")", ")", ";", "spTA", ".", "add", "(", "BorderLayout", ".", "CENTER", ",", "new", "JScrollPane", "(", "jTA", ")", ")", ";", "spTA", ".", "setBorder", "(", "BorderFactory", ".", "createTitledBorder", "(", "BorderFactory", ".", "createEtchedBorder", "(", ")", ",", "\"\"", ",", "TitledBorder", ".", "LEFT", ",", "TitledBorder", ".", "TOP", ")", ")", ";", "JPanel", "pAg", "=", "new", "JPanel", "(", "new", "BorderLayout", "(", ")", ")", ";", "pAg", ".", "add", "(", "BorderLayout", ".", "CENTER", ",", "spTA", ")", ";", "JButton", "jBtNext", "=", "new", "JButton", "(", "\"Next\"", ")", ";", "jBtNext", ".", "addActionListener", "(", "new", "ActionListener", "(", ")", "{", "public", "void", "actionPerformed", "(", "ActionEvent", "e", ")", "{", "SwingUtilities", ".", "invokeLater", "(", "new", "Runnable", "(", ")", "{", "public", "void", "run", "(", ")", "{", "step", "++", ";", "show", "(", ")", ";", "}", "}", ")", ";", "}", "}", ")", ";", "JButton", "jBtPrev", "=", "new", "JButton", "(", "\"Previous\"", ")", ";", "jBtPrev", ".", "addActionListener", "(", "new", "ActionListener", "(", ")", "{", "public", "void", "actionPerformed", "(", "ActionEvent", "e", ")", "{", "SwingUtilities", ".", "invokeLater", "(", "new", "Runnable", "(", ")", "{", "public", "void", "run", "(", ")", "{", "step", "--", ";", "show", "(", ")", ";", "}", "}", ")", ";", "}", "}", ")", ";", "JPanel", "pButtons", "=", "new", "JPanel", "(", "new", "FlowLayout", "(", "FlowLayout", ".", "CENTER", ")", ")", ";", "pButtons", ".", "add", "(", "jBtPrev", ")", ";", "pButtons", ".", "add", "(", "jBtNext", ")", ";", "JPanel", "pHistory", "=", "new", "JPanel", "(", "new", "BorderLayout", "(", ")", ")", ";", "pHistory", ".", "setBorder", "(", "BorderFactory", ".", "createTitledBorder", "(", "BorderFactory", ".", "createEtchedBorder", "(", ")", ",", "\"\"", ",", "TitledBorder", ".", "LEFT", ",", "TitledBorder", ".", "TOP", ")", ")", ";", "jHistory", "=", "new", "JSlider", "(", ")", ";", "jHistory", ".", "setMaximum", "(", "1", ")", ";", "jHistory", ".", "setMinimum", "(", "0", ")", ";", "jHistory", ".", "setValue", "(", "0", ")", ";", "jHistory", ".", "setPaintTicks", "(", "true", ")", ";", "jHistory", ".", "setPaintLabels", "(", "true", ")", ";", "jHistory", ".", "setMajorTickSpacing", "(", "10", ")", ";", "jHistory", ".", "setMinorTickSpacing", "(", "1", ")", ";", "setupSlider", "(", ")", ";", "jHistory", ".", "addChangeListener", "(", "new", "ChangeListener", "(", ")", "{", "public", "void", "stateChanged", "(", "ChangeEvent", "e", ")", "{", "step", "=", "(", "int", ")", "jHistory", ".", "getValue", "(", ")", ";", "show", "(", ")", ";", "}", "}", ")", ";", "pHistory", ".", "add", "(", "BorderLayout", ".", "CENTER", ",", "jHistory", ")", ";", "pHistory", ".", "add", "(", "BorderLayout", ".", "EAST", ",", "pButtons", ")", ";", "frame", ".", "getContentPane", "(", ")", ".", "add", "(", "BorderLayout", ".", "SOUTH", ",", "pHistory", ")", ";", "frame", ".", "getContentPane", "(", ")", ".", "add", "(", "BorderLayout", ".", "CENTER", ",", "pAg", ")", ";", "frame", ".", "pack", "(", ")", ";", "Dimension", "screenSize", "=", "Toolkit", ".", "getDefaultToolkit", "(", ")", ".", "getScreenSize", "(", ")", ";", "int", "height", "=", "(", "int", ")", "(", "screenSize", ".", "height", "*", "0.618", ")", ";", "frame", ".", "setBounds", "(", "80", ",", "30", ",", "(", "int", ")", "(", "height", "*", "1.2", ")", ",", "height", ")", ";", "frame", ".", "setVisible", "(", "true", ")", ";", "}", "private", "void", "show", "(", ")", "{", "try", "{", "frame", ".", "setTitle", "(", "\"\"", "+", "step", "+", "\"", "::\"", ")", ";", "Document", "agState", "=", "builder", ".", "parse", "(", "\"tmp-ag-mind/\"", "+", "step", "+", "\".xml\"", ")", ";", "jTA", ".", "setText", "(", "agTransformerHtml", ".", "transform", "(", "agState", ")", ")", ";", "jHistory", ".", "setValue", "(", "step", ")", ";", "}", "catch", "(", "Exception", "et", ")", "{", "et", ".", "printStackTrace", "(", ")", ";", "}", "}", "private", "void", "setupSlider", "(", ")", "{", "int", "first", "=", "-", "1", ";", "int", "size", "=", "0", ";", "for", "(", "String", "f", ":", "new", "File", "(", "\"\"", ")", ".", "list", "(", ")", ")", "{", "if", "(", "f", ".", "endsWith", "(", "\".xml\"", ")", ")", "{", "f", "=", "f", ".", "substring", "(", "0", ",", "f", ".", "length", "(", ")", "-", "4", ")", ";", "try", "{", "int", "n", "=", "Integer", ".", "parseInt", "(", "f", ")", ";", "if", "(", "first", "<", "0", ")", "first", "=", "n", ";", "if", "(", "n", ">", "size", ")", "size", "=", "n", ";", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}", "step", "=", "first", ";", "jHistory", ".", "setMinimum", "(", "first", ")", ";", "jHistory", ".", "setMaximum", "(", "size", ")", ";", "jHistory", ".", "setValue", "(", "step", ")", ";", "}", "}", "</s>" ]
9,142
[ "<s>", "package", "runtime", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "env", ".", "ClusterModelFactory", ";", "import", "env", ".", "CowModel", ";", "import", "env", ".", "CowModelFactory", ";", "import", "alice", ".", "cartago", ".", "*", ";", "import", "alice", ".", "cartago", ".", "tools", ".", "*", ";", "import", "alice", ".", "cartago", ".", "security", ".", "*", ";", "public", "class", "StartCartago", "{", "private", "static", "int", "port", "=", "22345", ";", "private", "static", "String", "end", "=", "\"\"", ";", "private", "static", "String", "wpsName1", "=", "\"cowmodel\"", ";", "private", "static", "String", "wpsName2", "=", "\"clustermodel\"", ";", "private", "static", "String", "cartagoRole", "=", "\"creator\"", ";", "private", "static", "String", "artName1", "=", "\"cModel\"", ";", "private", "static", "String", "artName2", "=", "\"clModel\"", ";", "private", "static", "String", "artClass1", "=", "\"\"", ";", "private", "static", "String", "artClass2", "=", "\"\"", ";", "private", "static", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "CowModel", ".", "class", ".", "getName", "(", ")", ")", ";", "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "UserCredential", "crcred", "=", "new", "UserIdCredential", "(", "cartagoRole", ")", ";", "CartagoService", ".", "installNode", "(", "port", ")", ";", "ICartagoContext", "ctx", "=", "CartagoService", ".", "joinWorkspace", "(", "\"default\"", ",", "end", ",", "cartagoRole", ",", "crcred", ")", ";", "ctx", ".", "createWorkspace", "(", "wpsName1", ")", ";", "ctx", ".", "createWorkspace", "(", "wpsName2", ")", ";", "ICartagoContext", "cModel", "=", "ctx", ".", "joinWorkspace", "(", "wpsName1", ",", "end", ",", "cartagoRole", ",", "crcred", ")", ";", "ICartagoContext", "clModel", "=", "ctx", ".", "joinWorkspace", "(", "wpsName2", ",", "end", ",", "cartagoRole", ",", "crcred", ")", ";", "if", "(", "!", "CowModelFactory", ".", "centralized", ")", "cModel", ".", "makeArtifact", "(", "artName1", ",", "artClass1", ",", "ArtifactConfig", ".", "DEFAULT_CONFIG", ",", "-", "1", ")", ";", "if", "(", "!", "ClusterModelFactory", ".", "centralized", ")", "clModel", ".", "makeArtifact", "(", "artName2", ",", "artClass2", ",", "ArtifactConfig", ".", "DEFAULT_CONFIG", ",", "-", "1", ")", ";", "}", "}", "</s>" ]
9,143
[ "<s>", "package", "agent", ";", "import", "jason", ".", "asSemantics", ".", "Agent", ";", "import", "jason", ".", "asSyntax", ".", "ASSyntax", ";", "import", "jason", ".", "asSyntax", ".", "InternalActionLiteral", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "asSyntax", ".", "Plan", ";", "import", "jason", ".", "asSyntax", ".", "PlanBody", ";", "import", "jason", ".", "asSyntax", ".", "PlanBodyImpl", ";", "import", "jason", ".", "asSyntax", ".", "Pred", ";", "import", "jason", ".", "asSyntax", ".", "directives", ".", "Directive", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "public", "class", "OrgMaintenanceGoal", "implements", "Directive", "{", "static", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "OrgMaintenanceGoal", ".", "class", ".", "getName", "(", ")", ")", ";", "public", "Agent", "process", "(", "Pred", "directive", ",", "Agent", "outerContent", ",", "Agent", "innerContent", ")", "{", "try", "{", "Agent", "newAg", "=", "new", "Agent", "(", ")", ";", "newAg", ".", "initAg", "(", ")", ";", "PlanBodyImpl", "endofplan", "=", "null", ";", "Literal", "goal", "=", "null", ";", "for", "(", "Plan", "p", ":", "innerContent", ".", "getPL", "(", ")", ")", "{", "InternalActionLiteral", "wait", "=", "new", "InternalActionLiteral", "(", "\".wait\"", ")", ";", "wait", ".", "addTerm", "(", "directive", ".", "getTerm", "(", "0", ")", ")", ";", "endofplan", "=", "new", "PlanBodyImpl", "(", "PlanBody", ".", "BodyType", ".", "internalAction", ",", "wait", ")", ";", "goal", "=", "p", ".", "getTrigger", "(", ")", ".", "getLiteral", "(", ")", ".", "copy", "(", ")", ";", "endofplan", ".", "add", "(", "new", "PlanBodyImpl", "(", "PlanBody", ".", "BodyType", ".", "achieveNF", ",", "goal", ")", ")", ";", "p", ".", "getBody", "(", ")", ".", "add", "(", "endofplan", ")", ";", "newAg", ".", "getPL", "(", ")", ".", "add", "(", "p", ",", "false", ")", ";", "}", "goal", "=", "goal", ".", "copy", "(", ")", ";", "goal", ".", "addAnnot", "(", "ASSyntax", ".", "parseStructure", "(", "\"error(EID)\"", ")", ")", ";", "goal", ".", "addAnnot", "(", "ASSyntax", ".", "parseStructure", "(", "\"\"", ")", ")", ";", "String", "sp", "=", "\"-!\"", "+", "goal", "+", "\"\"", "+", "\"\"", "+", "goal", ".", "getFunctor", "(", ")", "+", "\"\"", "+", "\"\"", "+", "endofplan", "+", "\".\"", ";", "Plan", "p", "=", "ASSyntax", ".", "parsePlan", "(", "sp", ")", ";", "newAg", ".", "getPL", "(", ")", ".", "add", "(", "p", ")", ";", "return", "newAg", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"\"", ",", "e", ")", ";", "}", "return", "null", ";", "}", "}", "</s>" ]
9,144
[ "<s>", "package", "agent", ";", "import", "jason", ".", "asSemantics", ".", "Agent", ";", "import", "jason", ".", "asSemantics", ".", "Event", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "asSyntax", ".", "Trigger", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Queue", ";", "public", "class", "SelectEvent", "extends", "Agent", "{", "private", "Trigger", "cow", "=", "Trigger", ".", "parseTrigger", "(", "\"+cow(_,_,_)\"", ")", ";", "private", "Trigger", "eos", "=", "Trigger", ".", "parseTrigger", "(", "\"\"", ")", ";", "private", "Unifier", "un", "=", "new", "Unifier", "(", ")", ";", "private", "boolean", "cleanCows", "=", "false", ";", "public", "Event", "selectEvent", "(", "Queue", "<", "Event", ">", "events", ")", "{", "Iterator", "<", "Event", ">", "ie", "=", "events", ".", "iterator", "(", ")", ";", "while", "(", "ie", ".", "hasNext", "(", ")", ")", "{", "un", ".", "clear", "(", ")", ";", "Event", "e", "=", "ie", ".", "next", "(", ")", ";", "if", "(", "un", ".", "unifies", "(", "eos", ",", "e", ".", "getTrigger", "(", ")", ")", ")", "{", "ie", ".", "remove", "(", ")", ";", "return", "e", ";", "}", "}", "return", "super", ".", "selectEvent", "(", "events", ")", ";", "}", "public", "void", "cleanCows", "(", ")", "{", "cleanCows", "=", "true", ";", "}", "@", "Override", "public", "void", "buf", "(", "List", "<", "Literal", ">", "percepts", ")", "{", "super", ".", "buf", "(", "percepts", ")", ";", "}", "}", "</s>" ]
9,145
[ "<s>", "package", "agent", ";", "import", "jason", ".", "asSemantics", ".", "Agent", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "bb", ".", "DefaultBeliefBase", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Set", ";", "public", "class", "DiscardBelsBB", "extends", "DefaultBeliefBase", "{", "Set", "<", "String", ">", "discartedBels", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "public", "void", "init", "(", "Agent", "ag", ",", "String", "[", "]", "args", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "discartedBels", ".", "add", "(", "args", "[", "i", "]", ")", ";", "}", "}", "@", "Override", "public", "boolean", "add", "(", "Literal", "bel", ")", "{", "if", "(", "!", "discartedBels", ".", "contains", "(", "bel", ".", "getFunctor", "(", ")", ")", ")", "{", "return", "super", ".", "add", "(", "bel", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "}", "</s>" ]
9,146
[ "<s>", "package", "agent", ";", "import", "jason", ".", "asSemantics", ".", "Agent", ";", "import", "jason", ".", "asSemantics", ".", "Unifier", ";", "import", "jason", ".", "asSyntax", ".", "Literal", ";", "import", "jason", ".", "asSyntax", ".", "NumberTerm", ";", "import", "jason", ".", "asSyntax", ".", "Structure", ";", "import", "jason", ".", "asSyntax", ".", "Term", ";", "import", "jason", ".", "bb", ".", "DefaultBeliefBase", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "public", "class", "UniqueBelsBB", "extends", "DefaultBeliefBase", "{", "Map", "<", "String", ",", "Literal", ">", "uniqueBels", "=", "new", "HashMap", "<", "String", ",", "Literal", ">", "(", ")", ";", "Unifier", "u", "=", "new", "Unifier", "(", ")", ";", "Agent", "myAgent", ";", "public", "void", "init", "(", "Agent", "ag", ",", "String", "[", "]", "args", ")", "{", "this", ".", "myAgent", "=", "ag", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "Literal", "arg", "=", "Literal", ".", "parseLiteral", "(", "args", "[", "i", "]", ")", ";", "uniqueBels", ".", "put", "(", "arg", ".", "getFunctor", "(", ")", ",", "arg", ")", ";", "}", "}", "@", "Override", "public", "boolean", "add", "(", "Literal", "bel", ")", "{", "Literal", "kb", "=", "uniqueBels", ".", "get", "(", "bel", ".", "getFunctor", "(", ")", ")", ";", "if", "(", "kb", "!=", "null", "&&", "kb", ".", "getArity", "(", ")", "==", "bel", ".", "getArity", "(", ")", ")", "{", "u", ".", "clear", "(", ")", ";", "Literal", "linbb", "=", "null", ";", "boolean", "remove", "=", "false", ";", "Iterator", "<", "Literal", ">", "relevant", "=", "getCandidateBeliefs", "(", "bel", ",", "null", ")", ";", "if", "(", "relevant", "!=", "null", ")", "{", "final", "int", "kbArity", "=", "kb", ".", "getArity", "(", ")", ";", "while", "(", "relevant", ".", "hasNext", "(", ")", "&&", "!", "remove", ")", "{", "linbb", "=", "relevant", ".", "next", "(", ")", ";", "boolean", "equals", "=", "true", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "kbArity", ";", "i", "++", ")", "{", "Term", "kbt", "=", "kb", ".", "getTerm", "(", "i", ")", ";", "if", "(", "!", "kbt", ".", "isVar", "(", ")", ")", "{", "if", "(", "!", "u", ".", "unifies", "(", "bel", ".", "getTerm", "(", "i", ")", ",", "linbb", ".", "getTerm", "(", "i", ")", ")", ")", "{", "equals", "=", "false", ";", "break", ";", "}", "}", "}", "if", "(", "equals", ")", "{", "remove", "=", "true", ";", "}", "}", "}", "if", "(", "remove", ")", "{", "remove", "(", "linbb", ")", ";", "}", "}", "return", "super", ".", "add", "(", "bel", ")", ";", "}", "public", "void", "remove_old_bels", "(", "Literal", "bel", ",", "String", "timeAnnot", ",", "int", "maxAge", ",", "int", "curAge", ")", "{", "Iterator", "<", "Literal", ">", "relevant", "=", "getCandidateBeliefs", "(", "bel", ",", "null", ")", ";", "if", "(", "relevant", "!=", "null", ")", "{", "List", "<", "Literal", ">", "toDel", "=", "new", "ArrayList", "<", "Literal", ">", "(", ")", ";", "while", "(", "relevant", ".", "hasNext", "(", ")", ")", "{", "Literal", "linbb", "=", "relevant", ".", "next", "(", ")", ";", "Structure", "bTime", "=", "null", ";", "if", "(", "linbb", ".", "hasAnnot", "(", ")", ")", "{", "for", "(", "Term", "t", ":", "linbb", ".", "getAnnots", "(", ")", ")", "{", "if", "(", "t", ".", "isStructure", "(", ")", ")", "{", "Structure", "s", "=", "(", "Structure", ")", "t", ";", "if", "(", "s", ".", "getFunctor", "(", ")", ".", "equals", "(", "timeAnnot", ")", ")", "{", "if", "(", "bTime", "==", "null", ")", "{", "bTime", "=", "s", ";", "}", "else", "if", "(", "bTime", ".", "compareTo", "(", "s", ")", "<", "0", ")", "{", "linbb", ".", "delAnnot", "(", "bTime", ")", ";", "bTime", "=", "s", ";", "}", "}", "}", "}", "if", "(", "bTime", "!=", "null", ")", "{", "int", "age", "=", "(", "int", ")", "(", "(", "NumberTerm", ")", "bTime", ".", "getTerm", "(", "0", ")", ")", ".", "solve", "(", ")", ";", "if", "(", "curAge", "-", "age", ">", "maxAge", ")", "toDel", ".", "add", "(", "linbb", ")", ";", "}", "}", "}", "for", "(", "Literal", "l", ":", "toDel", ")", "{", "myAgent", ".", "getLogger", "(", ")", ".", "info", "(", "\"Removing", "\"", "+", "l", "+", "\"\"", "+", "curAge", "+", "\")\"", ")", ";", "remove", "(", "l", ")", ";", "}", "}", "}", "}", "</s>" ]
9,147
[ "<s>", "package", "env", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "Collections", ";", "public", "class", "CowModel", "implements", "ICowModel", "{", "private", "Map", "<", "Integer", ",", "Cow", ">", "cows", "=", "Collections", ".", "synchronizedMap", "(", "new", "HashMap", "<", "Integer", ",", "Cow", ">", "(", ")", ")", ";", "private", "int", "[", "]", "[", "]", "grid", ";", "private", "int", "gH", "=", "-", "1", ",", "gW", "=", "-", "1", ";", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "CowModel", ".", "class", ".", "getName", "(", ")", ")", ";", "private", "int", "nop", "=", "0", ";", "public", "CowModel", "(", ")", "{", "}", "public", "synchronized", "void", "reset", "(", ")", "{", "cows", ".", "clear", "(", ")", ";", "gH", "=", "gW", "=", "-", "1", ";", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "public", "synchronized", "void", "setSize", "(", "int", "w", ",", "int", "h", ")", "{", "if", "(", "w", "==", "gW", "&&", "h", "==", "gH", ")", "return", ";", "reset", "(", ")", ";", "gW", "=", "w", ";", "gH", "=", "h", ";", "grid", "=", "new", "int", "[", "w", "+", "1", "]", "[", "h", "+", "1", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "w", ";", "i", "++", ")", "for", "(", "int", "j", "=", "0", ";", "j", "<=", "h", ";", "j", "++", ")", "grid", "[", "i", "]", "[", "j", "]", "=", "-", "1", ";", "logger", ".", "info", "(", "\"Got", "size:", "\"", "+", "gW", "+", "\",", "\"", "+", "gH", ")", ";", "}", "public", "void", "freePos", "(", "int", "x", ",", "int", "y", ")", "{", "synchronized", "(", "cows", ")", "{", "if", "(", "grid", "[", "x", "]", "[", "y", "]", "<", "0", ")", "return", ";", "cows", ".", "remove", "(", "grid", "[", "x", "]", "[", "y", "]", ")", ";", "grid", "[", "x", "]", "[", "y", "]", "=", "-", "1", ";", "}", "}", "public", "void", "insertCow", "(", "int", "id", ",", "int", "x", ",", "int", "y", ",", "int", "step", ")", "{", "synchronized", "(", "cows", ")", "{", "freePos", "(", "x", ",", "y", ")", ";", "Cow", "toRem", "=", "cows", ".", "get", "(", "id", ")", ";", "if", "(", "toRem", "!=", "null", ")", "{", "freePos", "(", "toRem", ".", "x", ",", "toRem", ".", "y", ")", ";", "}", "cows", ".", "put", "(", "id", ",", "new", "Cow", "(", "id", ",", "x", ",", "y", ",", "step", ")", ")", ";", "grid", "[", "x", "]", "[", "y", "]", "=", "id", ";", "}", "}", "public", "boolean", "checkState", "(", ")", "{", "String", "str", "=", "new", "String", "(", ")", ";", "int", "[", "]", "[", "]", "mapa", "=", "new", "int", "[", "gW", "+", "1", "]", "[", "gH", "+", "1", "]", ";", "nop", "=", "0", ";", "for", "(", "int", "x", "=", "0", ";", "x", "<=", "gW", ";", "++", "x", ")", "for", "(", "int", "y", "=", "0", ";", "y", "<=", "gH", ";", "++", "y", ")", "mapa", "[", "x", "]", "[", "y", "]", "=", "-", "1", ";", "synchronized", "(", "cows", ")", "{", "Iterator", "it", "=", "cows", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "Cow", "cw", "=", "cows", ".", "get", "(", "it", ".", "next", "(", ")", ")", ";", "if", "(", "mapa", "[", "cw", ".", "x", "]", "[", "cw", ".", "y", "]", ">=", "0", ")", "return", "false", ";", "mapa", "[", "cw", ".", "x", "]", "[", "cw", ".", "y", "]", "=", "cw", ".", "id", ";", "}", "for", "(", "int", "x", "=", "0", ";", "x", "<=", "gW", ";", "x", "++", ")", "for", "(", "int", "y", "=", "0", ";", "y", "<=", "gH", ";", "y", "++", ")", "if", "(", "mapa", "[", "x", "]", "[", "y", "]", "!=", "grid", "[", "x", "]", "[", "y", "]", ")", "{", "logger", ".", "info", "(", "\"position", "(\"", "+", "x", "+", "\",\"", "+", "y", "+", "\")", "\"", "+", "mapa", "[", "x", "]", "[", "y", "]", "+", "\"", "\"", "+", "grid", "[", "x", "]", "[", "y", "]", "+", "\"", "NOT", "OK\"", ")", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}", "public", "Cow", "[", "]", "getCows", "(", ")", "{", "Cow", "[", "]", "a", "=", "new", "Cow", "[", "cows", ".", "size", "(", ")", "]", ";", "return", "(", "Cow", "[", "]", ")", "(", "cows", ".", "values", "(", ")", ")", ".", "toArray", "(", "a", ")", ";", "}", "public", "void", "updateCows", "(", ")", "{", "}", "public", "int", "getSizeh", "(", ")", "{", "return", "gH", ";", "}", "public", "int", "getSizew", "(", ")", "{", "return", "gW", ";", "}", "}", "</s>" ]
9,148
[ "<s>", "package", "env", ";", "import", "java", ".", "lang", ".", "String", ";", "public", "class", "CowModelFactory", "{", "static", "private", "ICowModel", "cModel", ";", "static", "public", "boolean", "centralized", "=", "true", ";", "private", "static", "String", "end", "=", "\"\"", ";", "private", "static", "String", "wpsName", "=", "\"cowmodel\"", ";", "private", "static", "String", "cartagoRole", "=", "\"cowboy\"", ";", "private", "static", "String", "artName", "=", "\"cModel\"", ";", "public", "static", "ICowModel", "getModel", "(", "String", "agName", ")", "{", "if", "(", "centralized", ")", "{", "synchronized", "(", "CowModelFactory", ".", "class", ")", "{", "if", "(", "cModel", "==", "null", ")", "return", "cModel", "=", "new", "CowModel", "(", ")", ";", "else", "return", "cModel", ";", "}", "}", "else", "{", "try", "{", "Thread", ".", "sleep", "(", "3", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "new", "CCowModel", "(", "end", ",", "wpsName", ",", "cartagoRole", ",", "artName", ",", "agName", "+", "\"Co\"", "+", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "}", "}", "}", "</s>" ]
9,149
[ "<s>", "package", "env", ";", "public", "class", "configTable", "extends", "javax", ".", "swing", ".", "JFrame", "{", "IClusterModel", "clModel", ";", "public", "configTable", "(", ")", "{", "super", "(", "\"Tuner\"", ")", ";", "clModel", "=", "ClusterModelFactory", ".", "getModel", "(", "\"config\"", ")", ";", "initComponents", "(", ")", ";", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "void", "initComponents", "(", ")", "{", "jTextField1", "=", "new", "javax", ".", "swing", ".", "JTextField", "(", ")", ";", "jTabbedPane1", "=", "new", "javax", ".", "swing", ".", "JTabbedPane", "(", ")", ";", "jPanel1", "=", "new", "javax", ".", "swing", ".", "JPanel", "(", ")", ";", "jPanel2", "=", "new", "javax", ".", "swing", ".", "JPanel", "(", ")", ";", "jComboBox1", "=", "new", "javax", ".", "swing", ".", "JComboBox", "(", ")", ";", "jButton1", "=", "new", "javax", ".", "swing", ".", "JButton", "(", ")", ";", "jLabel1", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jComboBox2", "=", "new", "javax", ".", "swing", ".", "JComboBox", "(", ")", ";", "jLabel5", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jPanel3", "=", "new", "javax", ".", "swing", ".", "JPanel", "(", ")", ";", "jLabel2", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jLabel3", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jLabel4", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jSlider1", "=", "new", "javax", ".", "swing", ".", "JSlider", "(", "1", ",", "40", ",", "10", ")", ";", "jSlider2", "=", "new", "javax", ".", "swing", ".", "JSlider", "(", "1", ",", "100", ",", "50", ")", ";", "jButton2", "=", "new", "javax", ".", "swing", ".", "JButton", "(", ")", ";", "jLabel8", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jPanel4", "=", "new", "javax", ".", "swing", ".", "JPanel", "(", ")", ";", "jLabel6", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jLabel7", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jSlider3", "=", "new", "javax", ".", "swing", ".", "JSlider", "(", "1", ",", "200", ",", "100", ")", ";", "jButton3", "=", "new", "javax", ".", "swing", ".", "JButton", "(", ")", ";", "jLabel9", "=", "new", "javax", ".", "swing", ".", "JLabel", "(", ")", ";", "jTextField1", ".", "setText", "(", "\"jTextField1\"", ")", ";", "setDefaultCloseOperation", "(", "javax", ".", "swing", ".", "WindowConstants", ".", "DISPOSE_ON_CLOSE", ")", ";", "jPanel2", ".", "setBackground", "(", "new", "java", ".", "awt", ".", "Color", "(", "250", ",", "250", ",", "250", ")", ")", ";", "jComboBox1", ".", "setModel", "(", "new", "javax", ".", "swing", ".", "DefaultComboBoxModel", "(", "new", "String", "[", "]", "{", "\"\"", ",", "\"XMeans\"", ",", "\"CobWeb\"", ",", "\"sIB\"", ",", "\"\"", "}", ")", ")", ";", "jComboBox1", ".", "addActionListener", "(", "new", "java", ".", "awt", ".", "event", ".", "ActionListener", "(", ")", "{", "public", "void", "actionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "jComboBox1ActionPerformed", "(", "evt", ")", ";", "}", "}", ")", ";", "jButton1", ".", "setText", "(", "\"Change\"", ")", ";", "jButton1", ".", "addActionListener", "(", "new", "java", ".", "awt", ".", "event", ".", "ActionListener", "(", ")", "{", "public", "void", "actionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "jButton1ActionPerformed", "(", "evt", ")", ";", "}", "}", ")", ";", "jLabel1", ".", "setText", "(", "\"\"", ")", ";", "jComboBox2", ".", "setModel", "(", "new", "javax", ".", "swing", ".", "DefaultComboBoxModel", "(", "new", "String", "[", "]", "{", "\"\"", ",", "\"\"", ",", "\"\"", ",", "\"Median\"", "}", ")", ")", ";", "jComboBox2", ".", "setSelectedIndex", "(", "3", ")", ";", "jLabel5", ".", "setText", "(", "\"\"", ")", ";", "javax", ".", "swing", ".", "GroupLayout", "jPanel2Layout", "=", "new", "javax", ".", "swing", ".", "GroupLayout", "(", "jPanel2", ")", ";", "jPanel2", ".", "setLayout", "(", "jPanel2Layout", ")", ";", "jPanel2Layout", ".", "setHorizontalGroup", "(", "jPanel2Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel2Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addGroup", "(", "jPanel2Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jComboBox1", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addComponent", "(", "jLabel5", ")", ".", "addComponent", "(", "jLabel1", ")", ".", "addGroup", "(", "jPanel2Layout", ".", "createSequentialGroup", "(", ")", ".", "addComponent", "(", "jComboBox2", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ",", "355", ",", "Short", ".", "MAX_VALUE", ")", ".", "addComponent", "(", "jButton1", ")", ")", ")", ".", "addContainerGap", "(", ")", ")", ")", ";", "jPanel2Layout", ".", "setVerticalGroup", "(", "jPanel2Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel2Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addGroup", "(", "jPanel2Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel2Layout", ".", "createSequentialGroup", "(", ")", ".", "addComponent", "(", "jLabel1", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jComboBox1", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jLabel5", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ".", "addComponent", "(", "jComboBox2", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addGap", "(", "24", ",", "24", ",", "24", ")", ")", ".", "addGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "TRAILING", ",", "jPanel2Layout", ".", "createSequentialGroup", "(", ")", ".", "addComponent", "(", "jButton1", ")", ".", "addContainerGap", "(", ")", ")", ")", ")", ")", ";", "jPanel3", ".", "setBackground", "(", "new", "java", ".", "awt", ".", "Color", "(", "250", ",", "250", ",", "250", ")", ")", ";", "jLabel2", ".", "setText", "(", "\"\"", ")", ";", "jLabel3", ".", "setText", "(", "\"Ideal", "Size:\"", ")", ";", "jLabel4", ".", "setText", "(", "\"\"", ")", ";", "jSlider1", ".", "addChangeListener", "(", "new", "javax", ".", "swing", ".", "event", ".", "ChangeListener", "(", ")", "{", "public", "void", "stateChanged", "(", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", "evt", ")", "{", "jSlider1StateChanged", "(", "evt", ")", ";", "}", "}", ")", ";", "jSlider2", ".", "addChangeListener", "(", "new", "javax", ".", "swing", ".", "event", ".", "ChangeListener", "(", ")", "{", "public", "void", "stateChanged", "(", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", "evt", ")", "{", "jSlider2StateChanged", "(", "evt", ")", ";", "}", "}", ")", ";", "jButton2", ".", "setText", "(", "\"Change\"", ")", ";", "jButton2", ".", "addActionListener", "(", "new", "java", ".", "awt", ".", "event", ".", "ActionListener", "(", ")", "{", "public", "void", "actionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "jButton2ActionPerformed", "(", "evt", ")", ";", "}", "}", ")", ";", "jLabel8", ".", "setText", "(", "jSlider1", ".", "getValue", "(", ")", "+", "\",\"", "+", "jSlider2", ".", "getValue", "(", ")", ")", ";", "javax", ".", "swing", ".", "GroupLayout", "jPanel3Layout", "=", "new", "javax", ".", "swing", ".", "GroupLayout", "(", "jPanel3", ")", ";", "jPanel3", ".", "setLayout", "(", "jPanel3Layout", ")", ";", "jPanel3Layout", ".", "setHorizontalGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jLabel2", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createSequentialGroup", "(", ")", ".", "addGap", "(", "12", ",", "12", ",", "12", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jLabel3", ")", ".", "addComponent", "(", "jSlider1", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "143", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ",", "157", ",", "Short", ".", "MAX_VALUE", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ",", "false", ")", ".", "addComponent", "(", "jSlider2", ",", "0", ",", "143", ",", "Short", ".", "MAX_VALUE", ")", ".", "addComponent", "(", "jLabel4", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ")", ")", ".", "addGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "TRAILING", ",", "jPanel3Layout", ".", "createSequentialGroup", "(", ")", ".", "addComponent", "(", "jLabel8", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jButton2", ")", ")", ")", ".", "addContainerGap", "(", ")", ")", ")", ";", "jPanel3Layout", ".", "setVerticalGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addComponent", "(", "jLabel2", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "BASELINE", ")", ".", "addComponent", "(", "jLabel3", ")", ".", "addComponent", "(", "jLabel4", ")", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "TRAILING", ")", ".", "addComponent", "(", "jSlider2", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addComponent", "(", "jSlider1", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ".", "addGroup", "(", "jPanel3Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "BASELINE", ")", ".", "addComponent", "(", "jButton2", ")", ".", "addComponent", "(", "jLabel8", ")", ")", ".", "addContainerGap", "(", ")", ")", ")", ";", "jPanel4", ".", "setBackground", "(", "new", "java", ".", "awt", ".", "Color", "(", "250", ",", "250", ",", "250", ")", ")", ";", "jLabel6", ".", "setText", "(", "\"\"", ")", ";", "jLabel7", ".", "setText", "(", "\"k:\"", ")", ";", "jSlider3", ".", "addChangeListener", "(", "new", "javax", ".", "swing", ".", "event", ".", "ChangeListener", "(", ")", "{", "public", "void", "stateChanged", "(", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", "evt", ")", "{", "jSlider3StateChanged", "(", "evt", ")", ";", "}", "}", ")", ";", "jButton3", ".", "setText", "(", "\"Change\"", ")", ";", "jButton3", ".", "addActionListener", "(", "new", "java", ".", "awt", ".", "event", ".", "ActionListener", "(", ")", "{", "public", "void", "actionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "jButton3ActionPerformed", "(", "evt", ")", ";", "}", "}", ")", ";", "jLabel9", ".", "setText", "(", "jSlider3", ".", "getValue", "(", ")", "+", "\"\"", ")", ";", "javax", ".", "swing", ".", "GroupLayout", "jPanel4Layout", "=", "new", "javax", ".", "swing", ".", "GroupLayout", "(", "jPanel4", ")", ";", "jPanel4", ".", "setLayout", "(", "jPanel4Layout", ")", ";", "jPanel4Layout", ".", "setHorizontalGroup", "(", "jPanel4Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel4Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addGroup", "(", "jPanel4Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel4Layout", ".", "createSequentialGroup", "(", ")", ".", "addGap", "(", "12", ",", "12", ",", "12", ")", ".", "addComponent", "(", "jLabel7", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jSlider3", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ".", "addComponent", "(", "jLabel9", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jButton3", ")", ")", ".", "addComponent", "(", "jLabel6", ")", ")", ".", "addContainerGap", "(", ")", ")", ")", ";", "jPanel4Layout", ".", "setVerticalGroup", "(", "jPanel4Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel4Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addComponent", "(", "jLabel6", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addGroup", "(", "jPanel4Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jLabel7", ")", ".", "addComponent", "(", "jSlider3", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ")", ".", "addContainerGap", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ")", ".", "addGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "TRAILING", ",", "jPanel4Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", "46", ",", "Short", ".", "MAX_VALUE", ")", ".", "addGroup", "(", "jPanel4Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "BASELINE", ")", ".", "addComponent", "(", "jButton3", ")", ".", "addComponent", "(", "jLabel9", ")", ")", ".", "addContainerGap", "(", ")", ")", ")", ";", "javax", ".", "swing", ".", "GroupLayout", "jPanel1Layout", "=", "new", "javax", ".", "swing", ".", "GroupLayout", "(", "jPanel1", ")", ";", "jPanel1", ".", "setLayout", "(", "jPanel1Layout", ")", ";", "jPanel1Layout", ".", "setHorizontalGroup", "(", "jPanel1Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel1Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addGroup", "(", "jPanel1Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jPanel4", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "TRAILING", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ".", "addComponent", "(", "jPanel3", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ".", "addComponent", "(", "jPanel2", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ")", ".", "addContainerGap", "(", ")", ")", ")", ";", "jPanel1Layout", ".", "setVerticalGroup", "(", "jPanel1Layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addGroup", "(", "jPanel1Layout", ".", "createSequentialGroup", "(", ")", ".", "addContainerGap", "(", ")", ".", "addComponent", "(", "jPanel2", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jPanel3", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "139", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addPreferredGap", "(", "javax", ".", "swing", ".", "LayoutStyle", ".", "ComponentPlacement", ".", "RELATED", ")", ".", "addComponent", "(", "jPanel4", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "PREFERRED_SIZE", ")", ".", "addContainerGap", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "Short", ".", "MAX_VALUE", ")", ")", ")", ";", "jTabbedPane1", ".", "addTab", "(", "\"Clustering\"", ",", "jPanel1", ")", ";", "javax", ".", "swing", ".", "GroupLayout", "layout", "=", "new", "javax", ".", "swing", ".", "GroupLayout", "(", "getContentPane", "(", ")", ")", ";", "getContentPane", "(", ")", ".", "setLayout", "(", "layout", ")", ";", "layout", ".", "setHorizontalGroup", "(", "layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jTabbedPane1", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "515", ",", "Short", ".", "MAX_VALUE", ")", ")", ";", "layout", ".", "setVerticalGroup", "(", "layout", ".", "createParallelGroup", "(", "javax", ".", "swing", ".", "GroupLayout", ".", "Alignment", ".", "LEADING", ")", ".", "addComponent", "(", "jTabbedPane1", ",", "javax", ".", "swing", ".", "GroupLayout", ".", "DEFAULT_SIZE", ",", "443", ",", "Short", ".", "MAX_VALUE", ")", ")", ";", "pack", "(", ")", ";", "}", "private", "void", "jComboBox1ActionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "}", "private", "void", "jButton1ActionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "int", "a", "=", "jComboBox1", ".", "getSelectedIndex", "(", ")", ";", "IClusterModel", "clModel", "=", "ClusterModelFactory", ".", "getModel", "(", "\"config\"", ")", ";", "clModel", ".", "changeClusterer", "(", "a", "+", "1", ")", ";", "int", "b", "=", "jComboBox2", ".", "getSelectedIndex", "(", ")", ";", "clModel", ".", "changeMaxDist", "(", "b", "+", "1", ")", ";", "}", "private", "void", "jButton2ActionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "int", "a", "=", "jSlider1", ".", "getValue", "(", ")", ";", "int", "b", "=", "jSlider2", ".", "getValue", "(", ")", ";", "clModel", ".", "changeWCprop", "(", "a", ",", "b", ")", ";", "}", "private", "void", "jButton3ActionPerformed", "(", "java", ".", "awt", ".", "event", ".", "ActionEvent", "evt", ")", "{", "int", "a", "=", "jSlider3", ".", "getValue", "(", ")", ";", "clModel", ".", "changePTCprop", "(", "a", ")", ";", "}", "private", "void", "jSlider1StateChanged", "(", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", "evt", ")", "{", "jLabel8", ".", "setText", "(", "jSlider1", ".", "getValue", "(", ")", "+", "\",\"", "+", "jSlider2", ".", "getValue", "(", ")", ")", ";", "}", "private", "void", "jSlider2StateChanged", "(", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", "evt", ")", "{", "jLabel8", ".", "setText", "(", "jSlider1", ".", "getValue", "(", ")", "+", "\",\"", "+", "jSlider2", ".", "getValue", "(", ")", ")", ";", "}", "private", "void", "jSlider3StateChanged", "(", "javax", ".", "swing", ".", "event", ".", "ChangeEvent", "evt", ")", "{", "jLabel9", ".", "setText", "(", "jSlider3", ".", "getValue", "(", ")", "+", "\"\"", ")", ";", "}", "public", "static", "void", "main", "(", "String", "args", "[", "]", ")", "{", "java", ".", "awt", ".", "EventQueue", ".", "invokeLater", "(", "new", "Runnable", "(", ")", "{", "public", "void", "run", "(", ")", "{", "new", "configTable", "(", ")", ".", "setVisible", "(", "true", ")", ";", "}", "}", ")", ";", "}", "private", "javax", ".", "swing", ".", "JButton", "jButton1", ";", "private", "javax", ".", "swing", ".", "JButton", "jButton2", ";", "private", "javax", ".", "swing", ".", "JButton", "jButton3", ";", "private", "javax", ".", "swing", ".", "JComboBox", "jComboBox1", ";", "private", "javax", ".", "swing", ".", "JComboBox", "jComboBox2", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel1", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel2", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel3", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel4", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel5", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel6", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel7", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel8", ";", "private", "javax", ".", "swing", ".", "JLabel", "jLabel9", ";", "private", "javax", ".", "swing", ".", "JPanel", "jPanel1", ";", "private", "javax", ".", "swing", ".", "JPanel", "jPanel2", ";", "private", "javax", ".", "swing", ".", "JPanel", "jPanel3", ";", "private", "javax", ".", "swing", ".", "JPanel", "jPanel4", ";", "private", "javax", ".", "swing", ".", "JSlider", "jSlider1", ";", "private", "javax", ".", "swing", ".", "JSlider", "jSlider2", ";", "private", "javax", ".", "swing", ".", "JSlider", "jSlider3", ";", "private", "javax", ".", "swing", ".", "JTabbedPane", "jTabbedPane1", ";", "private", "javax", ".", "swing", ".", "JTextField", "jTextField1", ";", "}", "</s>" ]
9,150
[ "<s>", "package", "env", ";", "import", "weka", ".", "clusterers", ".", "ClusterEvaluation", ";", "import", "weka", ".", "clusterers", ".", "Clusterer", ";", "import", "weka", ".", "clusterers", ".", "Cobweb", ";", "import", "weka", ".", "clusterers", ".", "EM", ";", "import", "weka", ".", "clusterers", ".", "FarthestFirst", ";", "import", "weka", ".", "clusterers", ".", "XMeans", ";", "import", "weka", ".", "clusterers", ".", "sIB", ";", "import", "java", ".", "io", ".", "BufferedWriter", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "FileWriter", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Vector", ";", "import", "java", ".", "lang", ".", "Math", ";", "import", "jia", ".", "Vec", ";", "public", "class", "ClusterModel", "implements", "Runnable", ",", "IClusterModel", "{", "private", "boolean", "spc", "=", "true", ";", "private", "boolean", "useTuner", "=", "false", ";", "private", "int", "useClusterer", "=", "1", ";", "public", "static", "final", "int", "CLUSTERER_EM", "=", "1", ";", "public", "static", "final", "int", "CLUSTERER_XMEANS", "=", "2", ";", "public", "static", "final", "int", "CLUSTERER_COBWEB", "=", "3", ";", "public", "static", "final", "int", "CLUSTERER_sIB", "=", "4", ";", "public", "static", "final", "int", "CLUSTERER_FF", "=", "5", ";", "private", "int", "prefRadius", "=", "10", ",", "prefnCows", "=", "50", ",", "kPTC", "=", "100", ";", "private", "int", "useRadius", "=", "4", ";", "public", "static", "final", "int", "RADIUS_MAXDIST", "=", "1", ";", "public", "static", "final", "int", "RADIUS_SD", "=", "2", ";", "public", "static", "final", "int", "RADIUS_DBLDAVERAGE", "=", "3", ";", "final", "private", "static", "String", "NAME_FILE", "=", "\"cows.arff\"", ";", "final", "private", "static", "String", "CENTERS_NAME_FILE", "=", "\"centers.arff\"", ";", "private", "File", "file", ";", "private", "File", "previous", ";", "private", "int", "[", "]", "[", "]", "data", "=", "new", "int", "[", "2", "]", "[", "2", "]", ";", "private", "int", "dataNumber", ";", "private", "int", "[", "]", "alloc", "=", "new", "int", "[", "2", "]", ";", "private", "Vec", "[", "]", "Center", ";", "private", "int", "n", ";", "private", "int", "[", "]", "numcows", ";", "private", "int", "[", "]", "maxDist", ";", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "ClusterModel", ".", "class", ".", "getName", "(", ")", ")", ";", "ClusterEvaluation", "ce", ";", "private", "Cow", "[", "]", "cows", ";", "private", "int", "actStep", "=", "-", "1", ";", "private", "int", "clStep", ";", "private", "int", "[", "]", "s", ";", "private", "int", "gH", "=", "0", ";", "private", "int", "gW", "=", "0", ";", "private", "int", "[", "]", "[", "]", "cowsCluster", ";", "private", "boolean", "[", "]", "[", "]", "trees", ";", "final", "int", "DOWN", "=", "0", ",", "UP", "=", "1", ",", "LEFT", "=", "2", ",", "RIGHT", "=", "3", ";", "List", "<", "Integer", ">", "treeToAdd", "=", "new", "Vector", "<", "Integer", ">", "(", ")", ";", "ICowModel", "cModel", "=", "CowModelFactory", ".", "getModel", "(", "\"ClusterModel\"", ")", ";", "public", "ClusterModel", "(", ")", "{", "if", "(", "useTuner", ")", "{", "configTable", ".", "main", "(", "null", ")", ";", "}", "}", "public", "synchronized", "void", "run", "(", ")", "{", "if", "(", "actStep", "<", "clStep", ")", "{", "actStep", "=", "clStep", ";", "alloc", "=", "calculate", "(", ")", ";", "cCenters", "(", ")", ";", "setMap", "(", ")", ";", "cMaxDist", "(", ")", ";", "printClusters", "(", ")", ";", "}", "}", "private", "void", "printClusters", "(", ")", "{", "String", "str", "=", "new", "String", "(", ")", ";", "str", "=", "\"\"", "+", "n", "+", "\"|", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "str", "+=", "\"cluster", "\"", "+", "i", "+", "\"\"", "+", "Center", "[", "i", "]", ".", "getX", "(", ")", "+", "\",\"", "+", "(", "gH", "-", "Center", "[", "i", "]", ".", "getY", "(", ")", "-", "1", ")", "+", "\"\"", "+", "maxDist", "[", "i", "]", "+", "\"|\"", ";", "}", "logger", ".", "info", "(", "str", ")", ";", "}", "public", "int", "[", "]", "getMaxDist", "(", ")", "{", "return", "maxDist", ";", "}", "public", "void", "setStepcl", "(", "int", "step", ")", "{", "if", "(", "step", ">", "clStep", ")", "clStep", "=", "step", ";", "if", "(", "step", "==", "-", "1", ")", "{", "clStep", "=", "0", ";", "actStep", "=", "-", "1", ";", "}", "}", "private", "void", "cMaxDist", "(", ")", "{", "switch", "(", "useRadius", ")", "{", "case", "1", ":", "maxDist", "=", "new", "int", "[", "Center", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "int", "Dist", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getX", "(", ")", "-", "data", "[", "0", "]", "[", "i", "]", ")", ";", "int", "Dist2", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getY", "(", ")", "-", "data", "[", "1", "]", "[", "i", "]", ")", ";", "Dist", "=", "Math", ".", "max", "(", "Dist", ",", "Dist2", ")", ";", "if", "(", "Dist", ">", "maxDist", "[", "alloc", "[", "i", "]", "]", ")", "maxDist", "[", "alloc", "[", "i", "]", "]", "=", "Dist", ";", "}", "break", ";", "case", "2", ":", "maxDist", "=", "new", "int", "[", "Center", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "int", "Dist", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getX", "(", ")", "-", "data", "[", "0", "]", "[", "i", "]", ")", ";", "int", "Dist2", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getY", "(", ")", "-", "data", "[", "1", "]", "[", "i", "]", ")", ";", "Dist", "=", "Math", ".", "max", "(", "Dist", ",", "Dist2", ")", ";", "maxDist", "[", "alloc", "[", "i", "]", "]", "+=", "Dist", "*", "Dist", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "maxDist", ".", "length", ";", "i", "++", ")", "{", "maxDist", "[", "i", "]", "=", "(", "int", ")", "Math", ".", "sqrt", "(", "(", "double", ")", "maxDist", "[", "i", "]", "/", "(", "(", "double", ")", "numcows", "[", "i", "]", "-", "1.0", ")", ")", ";", "}", "break", ";", "case", "3", ":", "maxDist", "=", "new", "int", "[", "Center", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "int", "Dist", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getX", "(", ")", "-", "data", "[", "0", "]", "[", "i", "]", ")", ";", "int", "Dist2", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getY", "(", ")", "-", "data", "[", "1", "]", "[", "i", "]", ")", ";", "Dist", "=", "Math", ".", "max", "(", "Dist", ",", "Dist2", ")", ";", "maxDist", "[", "alloc", "[", "i", "]", "]", "+=", "Dist", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "maxDist", ".", "length", ";", "i", "++", ")", "{", "maxDist", "[", "i", "]", "=", "2", "*", "maxDist", "[", "i", "]", "/", "numcows", "[", "i", "]", ";", "}", "break", ";", "case", "4", ":", "Vec", "[", "]", "CenterTemp", "=", "new", "Vec", "[", "Center", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "CenterTemp", ".", "length", ";", "i", "++", ")", "{", "CenterTemp", "[", "i", "]", "=", "new", "Vec", "(", "0", ",", "0", ")", ";", "}", "float", "[", "]", "distOut", "=", "new", "float", "[", "Center", ".", "length", "]", ";", "Vector", "<", "Vector", "<", "Integer", ">", ">", "temp", "=", "new", "Vector", "<", "Vector", "<", "Integer", ">", ">", "(", ")", ";", "Vector", "<", "Vector", "<", "Integer", ">", ">", "temp2", "=", "new", "Vector", "<", "Vector", "<", "Integer", ">", ">", "(", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "Center", ".", "length", ";", "j", "++", ")", "{", "temp", ".", "add", "(", "new", "Vector", "<", "Integer", ">", "(", ")", ")", ";", "temp2", ".", "add", "(", "new", "Vector", "<", "Integer", ">", "(", ")", ")", ";", "}", "maxDist", "=", "new", "int", "[", "Center", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "int", "Dist", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getX", "(", ")", "-", "data", "[", "0", "]", "[", "i", "]", ")", ";", "int", "Dist2", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getY", "(", ")", "-", "data", "[", "1", "]", "[", "i", "]", ")", ";", "Dist", "=", "Math", ".", "max", "(", "Dist", ",", "Dist2", ")", ";", "temp", ".", "get", "(", "alloc", "[", "i", "]", ")", ".", "add", "(", "Dist", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "temp", ".", "size", "(", ")", ";", "i", "++", ")", "{", "Collections", ".", "sort", "(", "temp", ".", "get", "(", "i", ")", ")", ";", "if", "(", "temp", ".", "get", "(", "i", ")", ".", "size", "(", ")", "<=", "3", ")", "distOut", "[", "i", "]", "=", "0", ";", "else", "{", "int", "pos3Quartil", "=", "Math", ".", "round", "(", "(", "float", ")", "0.75", "*", "(", "temp", ".", "get", "(", "i", ")", ".", "size", "(", ")", "+", "1", ")", ")", "-", "1", ";", "int", "pos1Quartil", "=", "Math", ".", "round", "(", "(", "float", ")", "0.25", "*", "(", "temp", ".", "get", "(", "i", ")", ".", "size", "(", ")", "+", "1", ")", ")", "-", "1", ";", "distOut", "[", "i", "]", "=", "temp", ".", "get", "(", "i", ")", ".", "get", "(", "pos3Quartil", ")", "+", "(", "float", ")", "1.5", "*", "(", "temp", ".", "get", "(", "i", ")", ".", "get", "(", "pos3Quartil", ")", "-", "temp", ".", "get", "(", "i", ")", ".", "get", "(", "pos1Quartil", ")", ")", ";", "}", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "int", "Dist", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getX", "(", ")", "-", "data", "[", "0", "]", "[", "i", "]", ")", ";", "int", "Dist2", "=", "Math", ".", "abs", "(", "Center", "[", "alloc", "[", "i", "]", "]", ".", "getY", "(", ")", "-", "data", "[", "1", "]", "[", "i", "]", ")", ";", "Dist", "=", "Math", ".", "max", "(", "Dist", ",", "Dist2", ")", ";", "if", "(", "Dist", "<=", "distOut", "[", "alloc", "[", "i", "]", "]", "||", "(", "distOut", "[", "alloc", "[", "i", "]", "]", "<=", "0", ")", ")", "{", "temp2", ".", "get", "(", "alloc", "[", "i", "]", ")", ".", "add", "(", "Dist", ")", ";", "CenterTemp", "[", "alloc", "[", "i", "]", "]", "=", "CenterTemp", "[", "alloc", "[", "i", "]", "]", ".", "add", "(", "new", "Vec", "(", "data", "[", "0", "]", "[", "i", "]", ",", "data", "[", "1", "]", "[", "i", "]", ")", ")", ";", "}", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "temp2", ".", "size", "(", ")", ";", "i", "++", ")", "{", "Collections", ".", "sort", "(", "temp2", ".", "get", "(", "i", ")", ")", ";", "switch", "(", "temp2", ".", "get", "(", "i", ")", ".", "size", "(", ")", "%", "2", ")", "{", "case", "1", ":", "{", "maxDist", "[", "i", "]", "=", "2", "*", "temp2", ".", "get", "(", "i", ")", ".", "get", "(", "temp2", ".", "get", "(", "i", ")", ".", "size", "(", ")", "/", "2", ")", ";", "break", ";", "}", "case", "0", ":", "{", "maxDist", "[", "i", "]", "=", "temp2", ".", "get", "(", "i", ")", ".", "get", "(", "temp2", ".", "get", "(", "i", ")", ".", "size", "(", ")", "/", "2", ")", ";", "maxDist", "[", "i", "]", "+=", "temp2", ".", "get", "(", "i", ")", ".", "get", "(", "temp2", ".", "get", "(", "i", ")", ".", "size", "(", ")", "/", "2", "-", "1", ")", ";", "break", ";", "}", "}", "maxDist", "[", "i", "]", "+=", "1", ";", "CenterTemp", "[", "i", "]", "=", "CenterTemp", "[", "i", "]", ".", "newMagnitude", "(", "CenterTemp", "[", "i", "]", ".", "magnitude", "(", ")", "/", "(", "(", "double", ")", "temp2", ".", "get", "(", "i", ")", ".", "size", "(", ")", ")", ")", ";", "}", "Center", "=", "CenterTemp", ".", "clone", "(", ")", ";", "break", ";", "}", "}", "public", "int", "[", "]", "getAlloc", "(", ")", "{", "int", "[", "]", "al", "=", "alloc", ".", "clone", "(", ")", ";", "return", "al", ";", "}", "public", "int", "getNumberOfCluster", "(", ")", "{", "return", "n", ";", "}", "public", "int", "[", "]", "getNumCows", "(", ")", "{", "return", "numcows", ";", "}", "private", "void", "setMap", "(", ")", "{", "s", "=", "new", "int", "[", "1000", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "998", ";", "i", "++", ")", "s", "[", "i", "]", "=", "-", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "s", "[", "cows", "[", "i", "]", ".", "id", "]", "=", "alloc", "[", "i", "]", ";", "}", "}", "public", "int", "[", "]", "getMap", "(", ")", "{", "return", "s", ";", "}", "private", "void", "realloc", "(", ")", "{", "cowsCluster", "=", "new", "int", "[", "dataNumber", "]", "[", "dataNumber", "]", ";", "n", "=", "0", ";", "numcows", "=", "new", "int", "[", "dataNumber", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "if", "(", "alloc", "[", "i", "]", ">", "dataNumber", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "cowsCluster", "[", "alloc", "[", "i", "]", "]", "[", "numcows", "[", "alloc", "[", "i", "]", "]", "]", "=", "i", ";", "numcows", "[", "alloc", "[", "i", "]", "]", "++", ";", "if", "(", "alloc", "[", "i", "]", "+", "1", ">", "n", ")", "{", "n", "=", "alloc", "[", "i", "]", "+", "1", ";", "}", "}", "int", "[", "]", "temp2", "=", "new", "int", "[", "n", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "temp2", "[", "i", "]", "=", "numcows", "[", "i", "]", ";", "}", "numcows", "=", "temp2", ".", "clone", "(", ")", ";", "}", "private", "void", "cCenters", "(", ")", "{", "cowsCluster", "=", "new", "int", "[", "dataNumber", "]", "[", "dataNumber", "]", ";", "n", "=", "0", ";", "Center", "=", "new", "Vec", "[", "dataNumber", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "Center", "[", "i", "]", "=", "new", "Vec", "(", "0", ",", "0", ")", ";", "numcows", "=", "new", "int", "[", "dataNumber", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "if", "(", "alloc", "[", "i", "]", ">", "dataNumber", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "cowsCluster", "[", "alloc", "[", "i", "]", "]", "[", "numcows", "[", "alloc", "[", "i", "]", "]", "]", "=", "i", ";", "numcows", "[", "alloc", "[", "i", "]", "]", "++", ";", "if", "(", "alloc", "[", "i", "]", "+", "1", ">", "n", ")", "{", "n", "=", "alloc", "[", "i", "]", "+", "1", ";", "}", "Vec", "tmp", "=", "new", "Vec", "(", "data", "[", "0", "]", "[", "i", "]", ",", "data", "[", "1", "]", "[", "i", "]", ")", ";", "Center", "[", "alloc", "[", "i", "]", "]", "=", "Center", "[", "alloc", "[", "i", "]", "]", ".", "add", "(", "tmp", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "Center", "[", "i", "]", "=", "Center", "[", "i", "]", ".", "newMagnitude", "(", "Center", "[", "i", "]", ".", "magnitude", "(", ")", "/", "(", "(", "double", ")", "numcows", "[", "i", "]", ")", ")", ";", "}", "Vec", "[", "]", "temp", "=", "new", "Vec", "[", "n", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "temp", "[", "i", "]", "=", "(", "Vec", ")", "(", "Center", "[", "i", "]", ".", "clone", "(", ")", ")", ";", "}", "int", "[", "]", "temp2", "=", "new", "int", "[", "n", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "temp2", "[", "i", "]", "=", "numcows", "[", "i", "]", ";", "}", "numcows", "=", "temp2", ".", "clone", "(", ")", ";", "Center", "=", "temp", ".", "clone", "(", ")", ";", "}", "private", "void", "separateClusters", "(", ")", "{", "int", "[", "]", "[", "]", "datatmp", ";", "int", "[", "]", "[", "]", "extremes", "=", "new", "int", "[", "4", "]", "[", "n", "]", ";", "if", "(", "data", "==", "null", ")", "return", ";", "datatmp", "=", "data", ".", "clone", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "Vec", "cellUp", ";", "Vec", "cellDown", ";", "extremes", "[", "UP", "]", "[", "i", "]", "=", "extremes", "[", "DOWN", "]", "[", "i", "]", "=", "datatmp", "[", "1", "]", "[", "cowsCluster", "[", "i", "]", "[", "0", "]", "]", ";", "extremes", "[", "LEFT", "]", "[", "i", "]", "=", "extremes", "[", "RIGHT", "]", "[", "i", "]", "=", "datatmp", "[", "0", "]", "[", "cowsCluster", "[", "i", "]", "[", "0", "]", "]", ";", "cellUp", "=", "cellDown", "=", "new", "Vec", "(", "extremes", "[", "RIGHT", "]", "[", "i", "]", ",", "extremes", "[", "UP", "]", "[", "i", "]", ")", ";", "for", "(", "int", "j", "=", "1", ";", "j", "<", "numcows", "[", "i", "]", ";", "j", "++", ")", "{", "int", "x", "=", "datatmp", "[", "0", "]", "[", "cowsCluster", "[", "i", "]", "[", "j", "]", "]", ";", "int", "y", "=", "datatmp", "[", "1", "]", "[", "cowsCluster", "[", "i", "]", "[", "j", "]", "]", ";", "if", "(", "x", ">", "extremes", "[", "RIGHT", "]", "[", "i", "]", ")", "{", "extremes", "[", "RIGHT", "]", "[", "i", "]", "=", "x", ";", "}", "else", "if", "(", "x", "<", "extremes", "[", "LEFT", "]", "[", "i", "]", ")", "{", "extremes", "[", "LEFT", "]", "[", "i", "]", "=", "x", ";", "}", "if", "(", "y", ">", "extremes", "[", "UP", "]", "[", "i", "]", ")", "{", "extremes", "[", "UP", "]", "[", "i", "]", "=", "y", ";", "cellUp", "=", "new", "Vec", "(", "x", ",", "y", ")", ";", "}", "else", "if", "(", "y", "<", "extremes", "[", "DOWN", "]", "[", "i", "]", ")", "{", "extremes", "[", "DOWN", "]", "[", "i", "]", "=", "y", ";", "cellDown", "=", "new", "Vec", "(", "x", ",", "y", ")", ";", "}", "}", "List", "<", "Integer", ">", "Lista", "=", "new", "Vector", "<", "Integer", ">", "(", ")", ";", "Vec", "act", "=", "cellUp", ".", "sub", "(", "cellDown", ")", ";", "double", "mag", "=", "act", ".", "r", ";", "Vec", "init", "=", "new", "Vec", "(", "0", ",", "0", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "(", "int", ")", "mag", "+", "1", ";", "j", "++", ")", "{", "Vec", "position", "=", "cellDown", ".", "add", "(", "act", ".", "newMagnitude", "(", "j", ")", ")", ";", "int", "posx", "=", "(", "int", ")", "position", ".", "x", ";", "int", "posy", "=", "(", "int", ")", "position", ".", "y", ";", "if", "(", "trees", "[", "posx", "]", "[", "posy", "]", ")", "{", "init", "=", "new", "Vec", "(", "posx", ",", "posy", ")", ";", "}", "}", "int", "[", "]", "dx", "=", "{", "0", ",", "1", ",", "-", "1", "}", ";", "int", "[", "]", "dy", "=", "{", "-", "1", ",", "0", ",", "0", "}", ";", "Vec", "Up", "=", "goThroughCells", "(", "dx", ",", "dy", ",", "init", ",", "extremes", ",", "i", ")", ";", "dx", "[", "0", "]", "=", "0", ";", "dx", "[", "1", "]", "=", "1", ";", "dx", "[", "2", "]", "=", "-", "1", ";", "dy", "[", "0", "]", "=", "1", ";", "dy", "[", "1", "]", "=", "0", ";", "dy", "[", "2", "]", "=", "0", ";", "Vec", "Down", "=", "goThroughCells", "(", "dx", ",", "dy", ",", "init", ",", "extremes", ",", "i", ")", ";", "dx", "[", "0", "]", "=", "1", ";", "dx", "[", "1", "]", "=", "0", ";", "dx", "[", "2", "]", "=", "0", ";", "dy", "[", "0", "]", "=", "0", ";", "dy", "[", "1", "]", "=", "1", ";", "dy", "[", "2", "]", "=", "-", "1", ";", "Vec", "Left", "=", "goThroughCells", "(", "dx", ",", "dy", ",", "init", ",", "extremes", ",", "i", ")", ";", "dx", "[", "0", "]", "=", "-", "1", ";", "dx", "[", "1", "]", "=", "0", ";", "dx", "[", "2", "]", "=", "0", ";", "dy", "[", "0", "]", "=", "0", ";", "dy", "[", "1", "]", "=", "1", ";", "dy", "[", "2", "]", "=", "-", "1", ";", "Vec", "Right", "=", "goThroughCells", "(", "dx", ",", "dy", ",", "init", ",", "extremes", ",", "i", ")", ";", "Vec", "D2U", "=", "Up", ".", "sub", "(", "Down", ")", ";", "Vec", "L2R", "=", "Right", ".", "sub", "(", "Left", ")", ";", "for", "(", "int", "cow", ":", "cowsCluster", "[", "i", "]", ")", "{", "if", "(", "D2U", ".", "dot", "(", "new", "Vec", "(", "data", "[", "0", "]", "[", "cow", "]", ",", "data", "[", "1", "]", "[", "cow", "]", ")", ")", "<", "0", ")", "{", "Lista", ".", "add", "(", "cow", ")", ";", "}", "}", "if", "(", "Lista", ".", "size", "(", ")", ">", "0", "&&", "Lista", ".", "size", "(", ")", "!=", "numcows", "[", "i", "]", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "Lista", ".", "size", "(", ")", ";", "j", "++", ")", "{", "alloc", "[", "Lista", ".", "get", "(", "j", ")", "]", "=", "n", ";", "}", "n", "++", ";", "}", "realloc", "(", ")", ";", "for", "(", "int", "cow", ":", "cowsCluster", "[", "i", "]", ")", "{", "if", "(", "L2R", ".", "dot", "(", "new", "Vec", "(", "data", "[", "0", "]", "[", "cow", "]", ",", "data", "[", "1", "]", "[", "cow", "]", ")", ")", "<", "0", ")", "{", "Lista", ".", "add", "(", "cow", ")", ";", "}", "}", "if", "(", "Lista", ".", "size", "(", ")", ">", "0", "&&", "Lista", ".", "size", "(", ")", "!=", "numcows", "[", "i", "]", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "Lista", ".", "size", "(", ")", ";", "j", "++", ")", "{", "alloc", "[", "Lista", ".", "get", "(", "j", ")", "]", "=", "n", ";", "}", "n", "++", ";", "}", "}", "}", "private", "Vec", "goThroughCells", "(", "int", "dx", "[", "]", ",", "int", "dy", "[", "]", ",", "Vec", "beg", ",", "int", "[", "]", "[", "]", "extremes", ",", "int", "Cluster", ")", "{", "Vec", "cur", "=", "beg", ";", "boolean", "nextOk", ";", "while", "(", "true", ")", "{", "nextOk", "=", "false", ";", "Vec", "cur2", "=", "cur", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dx", ".", "length", ";", "i", "++", ")", "{", "cur2", "=", "cur", ".", "add", "(", "new", "Vec", "(", "dx", "[", "i", "]", "+", "0.1", ",", "dy", "[", "i", "]", "+", "0.1", ")", ")", ";", "if", "(", "isIn", "(", "(", "int", ")", "cur2", ".", "x", ",", "(", "int", ")", "cur2", ".", "y", ",", "extremes", ",", "Cluster", ")", "&&", "trees", "[", "(", "int", ")", "cur2", ".", "x", "]", "[", "(", "int", ")", "cur2", ".", "y", "]", ")", "{", "nextOk", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "nextOk", ")", "{", "beg", "=", "cur", ";", "break", ";", "}", "else", "{", "cur", "=", "cur2", ";", "}", "}", "return", "beg", ";", "}", "private", "boolean", "isIn", "(", "int", "x", ",", "int", "y", ",", "int", "[", "]", "[", "]", "extremes", ",", "int", "Cluster", ")", "{", "if", "(", "x", ">", "extremes", "[", "RIGHT", "]", "[", "Cluster", "]", ")", "return", "false", ";", "if", "(", "x", "<", "extremes", "[", "LEFT", "]", "[", "Cluster", "]", ")", "return", "false", ";", "if", "(", "y", ">", "extremes", "[", "UP", "]", "[", "Cluster", "]", ")", "return", "false", ";", "if", "(", "y", "<", "extremes", "[", "DOWN", "]", "[", "Cluster", "]", ")", "return", "false", ";", "return", "true", ";", "}", "private", "void", "printCenters", "(", ")", "{", "Vec", "[", "]", "c", "=", "Center", ".", "clone", "(", ")", ";", "String", "str", "=", "new", "String", "(", ")", ";", "str", "+=", "\">\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "c", ".", "length", ";", "i", "++", ")", "{", "logger", ".", "info", "(", "str", ")", ";", "str", "+=", "\"", "[\"", "+", "i", "+", "\"]\"", "+", "\"(\"", "+", "(", "int", ")", "c", "[", "i", "]", ".", "x", "+", "\",\"", "+", "(", "int", ")", "c", "[", "i", "]", ".", "y", "+", "\")\"", ";", "}", "logger", ".", "info", "(", "str", ")", ";", "}", "public", "Vec", "[", "]", "getCenters", "(", ")", "{", "return", "Center", ";", "}", "public", "int", "[", "]", "[", "]", "getData", "(", ")", "{", "return", "data", ".", "clone", "(", ")", ";", "}", "private", "void", "createCentersFile", "(", ")", "{", "try", "{", "previous", "=", "new", "File", "(", "CENTERS_NAME_FILE", ")", ";", "if", "(", "!", "previous", ".", "exists", "(", ")", ")", "previous", ".", "createNewFile", "(", ")", ";", "BufferedWriter", "out", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "previous", ",", "false", ")", ")", ";", "out", ".", "write", "(", "\"\"", ")", ";", "out", ".", "write", "(", "\"\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "Center", ".", "length", ";", "i", "++", ")", "{", "out", ".", "write", "(", "Center", "[", "i", "]", ".", "getX", "(", ")", "+", "\",\"", "+", "Center", "[", "i", "]", ".", "getY", "(", ")", "+", "\"n\"", ")", ";", "}", "out", ".", "write", "(", "\"n\"", ")", ";", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "private", "void", "createFile", "(", ")", "{", "int", "i", ";", "try", "{", "file", "=", "new", "File", "(", "NAME_FILE", ")", ";", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "file", ".", "createNewFile", "(", ")", ";", "BufferedWriter", "out", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "file", ",", "false", ")", ")", ";", "out", ".", "write", "(", "\"\"", ")", ";", "out", ".", "write", "(", "\"\"", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "out", ".", "write", "(", "data", "[", "0", "]", "[", "i", "]", "+", "\",\"", "+", "data", "[", "1", "]", "[", "i", "]", "+", "\"n\"", ")", ";", "out", ".", "write", "(", "\"n\"", ")", ";", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "private", "void", "defineData", "(", "int", "[", "]", "[", "]", "inf", ")", "{", "data", "=", "inf", ".", "clone", "(", ")", ";", "}", "public", "void", "changeClusterer", "(", "int", "a", ")", "{", "useClusterer", "=", "a", ";", "}", "public", "void", "changeMaxDist", "(", "int", "a", ")", "{", "useRadius", "=", "a", ";", "}", "public", "void", "changeWCprop", "(", "int", "radius", ",", "int", "nCows", ")", "{", "prefRadius", "=", "radius", ";", "prefnCows", "=", "nCows", ";", "}", "public", "int", "getPrefRadius", "(", ")", "{", "return", "prefRadius", ";", "}", "public", "int", "getPrefNCows", "(", ")", "{", "return", "prefnCows", ";", "}", "public", "void", "changePTCprop", "(", "int", "k", ")", "{", "kPTC", "=", "k", ";", "}", "public", "double", "getPrefkPTC", "(", ")", "{", "return", "(", "double", ")", "kPTC", "/", "100.0", ";", "}", "synchronized", "public", "void", "insertTree", "(", "int", "x", ",", "int", "y", ")", "{", "if", "(", "!", "(", "x", ">=", "gW", "||", "x", "<", "0", "||", "y", ">=", "gH", "||", "y", "<", "0", ")", ")", "{", "while", "(", "treeToAdd", ".", "size", "(", ")", ">", "0", ")", "{", "int", "tmp", "=", "treeToAdd", ".", "remove", "(", "0", ")", ";", "insertTree", "(", "tmp", "/", "10000", ",", "tmp", "%", "10000", ")", ";", "}", "try", "{", "trees", "[", "x", "]", "[", "-", "y", "+", "gH", "-", "1", "]", "=", "true", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "else", "{", "if", "(", "gW", "==", "0", "||", "gH", "==", "0", ")", "{", "treeToAdd", ".", "add", "(", "x", "*", "10000", "+", "y", ")", ";", "}", "}", "}", "public", "void", "setCows", "(", "Cow", "[", "]", "c", ",", "int", "H", ",", "int", "W", ")", "{", "spc", "=", "false", ";", "cows", "=", "c", ";", "gH", "=", "H", ";", "gW", "=", "W", ";", "}", "private", "int", "[", "]", "calculate", "(", ")", "{", "ce", "=", "new", "ClusterEvaluation", "(", ")", ";", "int", "countStepsWithProblem", "=", "0", ";", "if", "(", "spc", ")", "{", "cModel", ".", "updateCows", "(", ")", ";", "cows", "=", "cModel", ".", "getCows", "(", ")", ";", "while", "(", "gH", "<=", "0", "||", "gW", "<=", "0", "||", "clStep", "==", "-", "1", ")", "{", "gH", "=", "cModel", ".", "getSizeh", "(", ")", ";", "gW", "=", "cModel", ".", "getSizew", "(", ")", ";", "if", "(", "countStepsWithProblem", "++", ">", "20", ")", "{", "break", ";", "}", "}", "}", "if", "(", "cows", "==", "null", "||", "cows", ".", "length", "<=", "0", ")", "{", "dataNumber", "=", "0", ";", "gH", "=", "gW", "=", "0", ";", "}", "else", "dataNumber", "=", "cows", ".", "length", ";", "trees", "=", "new", "boolean", "[", "gW", "]", "[", "gH", "]", ";", "int", "[", "]", "[", "]", "infos", "=", "new", "int", "[", "2", "]", "[", "dataNumber", "]", ";", "if", "(", "dataNumber", "==", "0", ")", "return", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "infos", "[", "0", "]", "[", "i", "]", "=", "cows", "[", "i", "]", ".", "x", ";", "infos", "[", "1", "]", "[", "i", "]", "=", "gH", "-", "1", "-", "cows", "[", "i", "]", ".", "y", ";", "}", "defineData", "(", "infos", ")", ";", "createFile", "(", ")", ";", "Clusterer", "cluster", "=", "null", ";", "String", "[", "]", "options", "=", "null", ";", "switch", "(", "useClusterer", ")", "{", "case", "1", ":", "cluster", "=", "new", "EM", "(", ")", ";", "options", "=", "new", "String", "[", "4", "]", ";", "options", "[", "0", "]", "=", "\"-t\"", ";", "options", "[", "1", "]", "=", "file", ".", "getAbsolutePath", "(", ")", ";", "options", "[", "2", "]", "=", "\"-p\"", ";", "options", "[", "3", "]", "=", "\"0\"", ";", "break", ";", "case", "2", ":", "cluster", "=", "new", "XMeans", "(", ")", ";", "options", "=", "new", "String", "[", "8", "]", ";", "options", "[", "0", "]", "=", "\"-t\"", ";", "options", "[", "1", "]", "=", "file", ".", "getAbsolutePath", "(", ")", ";", "options", "[", "2", "]", "=", "\"-p\"", ";", "options", "[", "3", "]", "=", "\"0\"", ";", "options", "[", "4", "]", "=", "\"-H\"", ";", "options", "[", "5", "]", "=", "\"6\"", ";", "options", "[", "6", "]", "=", "\"-D\"", ";", "options", "[", "7", "]", "=", "\"\"", ";", "break", ";", "case", "3", ":", "cluster", "=", "new", "Cobweb", "(", ")", ";", "options", "=", "new", "String", "[", "4", "]", ";", "options", "[", "0", "]", "=", "\"-t\"", ";", "options", "[", "1", "]", "=", "file", ".", "getAbsolutePath", "(", ")", ";", "options", "[", "2", "]", "=", "\"-p\"", ";", "options", "[", "3", "]", "=", "\"0\"", ";", "break", ";", "case", "4", ":", "cluster", "=", "new", "sIB", "(", ")", ";", "options", "=", "new", "String", "[", "4", "]", ";", "options", "[", "0", "]", "=", "\"-t\"", ";", "options", "[", "1", "]", "=", "file", ".", "getAbsolutePath", "(", ")", ";", "options", "[", "2", "]", "=", "\"-p\"", ";", "options", "[", "3", "]", "=", "\"0\"", ";", "break", ";", "case", "5", ":", "cluster", "=", "new", "FarthestFirst", "(", ")", ";", "options", "=", "new", "String", "[", "4", "]", ";", "options", "[", "0", "]", "=", "\"-t\"", ";", "options", "[", "1", "]", "=", "file", ".", "getAbsolutePath", "(", ")", ";", "options", "[", "2", "]", "=", "\"-p\"", ";", "options", "[", "3", "]", "=", "\"0\"", ";", "break", ";", "}", "try", "{", "String", "str", "=", "ClusterEvaluation", ".", "evaluateClusterer", "(", "cluster", ",", "options", ")", ";", "logger", ".", "info", "(", "\"\"", "+", "useClusterer", ")", ";", "int", "[", "]", "assign", "=", "new", "int", "[", "dataNumber", "]", ";", "String", "[", "]", "tmp", "=", "str", ".", "split", "(", "\"n\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dataNumber", ";", "i", "++", ")", "{", "assign", "[", "i", "]", "=", "(", "int", ")", "(", "Double", ".", "parseDouble", "(", "tmp", "[", "i", "]", ".", "split", "(", "\"", "\"", ")", "[", "1", "]", ")", "+", "0.1", ")", ";", "}", "return", "assign", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "null", ";", "}", "public", "void", "update", "(", ")", "{", "}", "}", "</s>" ]
9,151
[ "<s>", "package", "env", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "alice", ".", "cartago", ".", "*", ";", "public", "class", "ClusterModelArtifact", "extends", "Artifact", "{", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "ClusterModelArtifact", ".", "class", ".", "getName", "(", ")", ")", ";", "private", "ClusterModel", "model", "=", "ClusterModelFactory", ".", "getModelCent", "(", ")", ";", "@", "OPERATION", "void", "init", "(", ")", "{", "new", "Thread", "(", "(", "Runnable", ")", "model", ")", ".", "start", "(", ")", ";", "defineObsProperty", "(", "\"clusterAlloc\"", ",", "model", ".", "getAlloc", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getCenters", "(", ")", ")", ";", "defineObsProperty", "(", "\"clusterData\"", ",", "model", ".", "getData", "(", ")", ")", ";", "defineObsProperty", "(", "\"clusterMap\"", ",", "model", ".", "getMap", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getMaxDist", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getNumCows", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getNumberOfCluster", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getPrefNCows", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getPrefRadius", "(", ")", ")", ";", "defineObsProperty", "(", "\"\"", ",", "model", ".", "getPrefkPTC", "(", ")", ")", ";", "logger", ".", "info", "(", "\"inicializou\"", ")", ";", "}", "@", "OPERATION", "void", "update", "(", ")", "{", "logger", ".", "info", "(", "\"\"", ")", ";", "updateObsProperty", "(", "\"clusterAlloc\"", ",", "model", ".", "getAlloc", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getCenters", "(", ")", ")", ";", "updateObsProperty", "(", "\"clusterData\"", ",", "model", ".", "getData", "(", ")", ")", ";", "updateObsProperty", "(", "\"clusterMap\"", ",", "model", ".", "getMap", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getMaxDist", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getNumCows", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getNumberOfCluster", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getPrefNCows", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getPrefRadius", "(", ")", ")", ";", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getPrefkPTC", "(", ")", ")", ";", "logger", ".", "info", "(", "\"\"", "+", "model", ".", "getPrefkPTC", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateAlloc", "(", ")", "{", "updateObsProperty", "(", "\"clusterAlloc\"", ",", "model", ".", "getAlloc", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateCenters", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getCenters", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateData", "(", ")", "{", "updateObsProperty", "(", "\"clusterData\"", ",", "model", ".", "getData", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateMap", "(", ")", "{", "updateObsProperty", "(", "\"clusterMap\"", ",", "model", ".", "getMap", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateRadius", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getMaxDist", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateNumCows", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getNumCows", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updateClusterNumber", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getNumberOfCluster", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updatePrefNCows", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getPrefNCows", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updatePrefRadius", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getPrefRadius", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "updatePrefKPTC", "(", ")", "{", "updateObsProperty", "(", "\"\"", ",", "model", ".", "getPrefkPTC", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "clusterCClusterer", "(", "int", "a", ")", "{", "model", ".", "changeClusterer", "(", "a", ")", ";", "}", "@", "OPERATION", "void", "clusterInsertTree", "(", "int", "x", ",", "int", "y", ")", "{", "model", ".", "insertTree", "(", "x", ",", "y", ")", ";", "}", "@", "OPERATION", "void", "clusterSetStep", "(", "int", "step", ")", "{", "model", ".", "setStepcl", "(", "step", ")", ";", "}", "@", "OPERATION", "void", "clusterRun", "(", ")", "{", "new", "Thread", "(", "(", "Runnable", ")", "model", ")", ".", "start", "(", ")", ";", "}", "@", "OPERATION", "void", "clustercMaxDist", "(", "int", "a", ")", "{", "model", ".", "changeMaxDist", "(", "a", ")", ";", "}", "@", "OPERATION", "void", "clusterSetCows", "(", "Cow", "[", "]", "c", ",", "int", "H", ",", "int", "W", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "c", ".", "length", ")", ";", "model", ".", "setCows", "(", "c", ",", "H", ",", "W", ")", ";", "}", "@", "OPERATION", "void", "clusterPTCP", "(", "int", "k", ")", "{", "model", ".", "changePTCprop", "(", "k", ")", ";", "}", "@", "OPERATION", "void", "clusterWCP", "(", "int", "radius", ",", "int", "nCows", ")", "{", "model", ".", "changeWCprop", "(", "radius", ",", "nCows", ")", ";", "}", "}", "</s>" ]
9,152
[ "<s>", "package", "env", ";", "public", "interface", "ICowModel", "{", "public", "void", "reset", "(", ")", ";", "public", "void", "setSize", "(", "int", "w", ",", "int", "h", ")", ";", "public", "void", "freePos", "(", "int", "x", ",", "int", "y", ")", ";", "public", "void", "insertCow", "(", "int", "id", ",", "int", "x", ",", "int", "y", ",", "int", "step", ")", ";", "public", "void", "updateCows", "(", ")", ";", "public", "Cow", "[", "]", "getCows", "(", ")", ";", "public", "int", "getSizeh", "(", ")", ";", "public", "int", "getSizew", "(", ")", ";", "}", "</s>" ]
9,153
[ "<s>", "package", "env", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "alice", ".", "cartago", ".", "security", ".", "*", ";", "import", "alice", ".", "cartago", ".", "*", ";", "import", "java", ".", "lang", ".", "String", ";", "public", "class", "CCowModel", "implements", "ICowModel", "{", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "CowModel", ".", "class", ".", "getName", "(", ")", ")", ";", "private", "UserCredential", "cred", ";", "private", "ICartagoContext", "cWps", ";", "private", "ArtifactId", "cArt", ";", "private", "String", "end", ";", "private", "String", "wpsName", ";", "private", "String", "cartagoRole", ";", "private", "String", "artName", ";", "private", "int", "gW", ",", "gH", ";", "private", "Cow", "[", "]", "cows", ";", "public", "CCowModel", "(", "String", "end", ",", "String", "wpsName", ",", "String", "cartagoRole", ",", "String", "artName", ",", "String", "agName", ")", "{", "this", ".", "end", "=", "end", ";", "this", ".", "wpsName", "=", "wpsName", ";", "this", ".", "cartagoRole", "=", "cartagoRole", ";", "this", ".", "artName", "=", "artName", ";", "cred", "=", "new", "UserIdCredential", "(", "agName", ")", ";", "try", "{", "cWps", "=", "CartagoService", ".", "joinWorkspace", "(", "this", ".", "wpsName", ",", "this", ".", "end", ",", "this", ".", "cartagoRole", ",", "cred", ")", ";", "cArt", "=", "cWps", ".", "lookupArtifact", "(", "this", ".", "artName", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "synchronized", "void", "reset", "(", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"init\"", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "logger", ".", "info", "(", "\"\"", ")", ";", "}", "public", "synchronized", "void", "setSize", "(", "int", "w", ",", "int", "h", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"cSetSize\"", ",", "w", ",", "h", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "logger", ".", "info", "(", "\"Got", "size:", "\"", "+", "w", "+", "\",", "\"", "+", "h", ")", ";", "}", "public", "void", "freePos", "(", "int", "x", ",", "int", "y", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"cFreePos\"", ",", "x", ",", "y", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "}", "public", "void", "insertCow", "(", "int", "id", ",", "int", "x", ",", "int", "y", ",", "int", "step", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"cInsertCow\"", ",", "id", ",", "x", ",", "y", ",", "step", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "}", "public", "void", "updateCows", "(", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "try", "{", "gH", "=", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"H\"", ")", ".", "intValue", "(", ")", ";", "gW", "=", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"W\"", ")", ".", "intValue", "(", ")", ";", "cows", "=", "(", "Cow", "[", "]", ")", "(", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"cowprop\"", ")", ".", "getValue", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "}", "public", "Cow", "[", "]", "getCows", "(", ")", "{", "return", "cows", ";", "}", "public", "int", "getSizeh", "(", ")", "{", "return", "gH", ";", "}", "public", "int", "getSizew", "(", ")", "{", "return", "gW", ";", "}", "}", "</s>" ]
9,154
[ "<s>", "package", "env", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "alice", ".", "cartago", ".", "*", ";", "public", "class", "CowModelArtifact", "extends", "Artifact", "{", "CowModel", "cModel", "=", "new", "CowModel", "(", ")", ";", "@", "OPERATION", "void", "init", "(", ")", "{", "cModel", ".", "reset", "(", ")", ";", "defineObsProperty", "(", "\"cowprop\"", ",", "cModel", ".", "getCows", "(", ")", ")", ";", "defineObsProperty", "(", "\"H\"", ",", "cModel", ".", "getSizeh", "(", ")", ")", ";", "defineObsProperty", "(", "\"W\"", ",", "cModel", ".", "getSizew", "(", ")", ")", ";", "}", "@", "OPERATION", "void", "cInsertCow", "(", "int", "id", ",", "int", "x", ",", "int", "y", ",", "int", "step", ")", "{", "cModel", ".", "insertCow", "(", "id", ",", "x", ",", "y", ",", "step", ")", ";", "}", "@", "OPERATION", "void", "cFreePos", "(", "int", "x", ",", "int", "y", ")", "{", "cModel", ".", "freePos", "(", "x", ",", "y", ")", ";", "}", "@", "OPERATION", "void", "cSetSize", "(", "int", "w", ",", "int", "h", ")", "{", "cModel", ".", "setSize", "(", "w", ",", "h", ")", ";", "}", "@", "OPERATION", "void", "updateProperty", "(", ")", "{", "updateObsProperty", "(", "\"cowprop\"", ",", "cModel", ".", "getCows", "(", ")", ")", ";", "updateObsProperty", "(", "\"H\"", ",", "cModel", ".", "getSizeh", "(", ")", ")", ";", "updateObsProperty", "(", "\"W\"", ",", "cModel", ".", "getSizew", "(", ")", ")", ";", "}", "}", "</s>" ]
9,155
[ "<s>", "package", "env", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Area", ";", "import", "jason", ".", "environment", ".", "grid", ".", "GridWorldModel", ";", "import", "jason", ".", "environment", ".", "grid", ".", "Location", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "public", "class", "WorldModel", "extends", "GridWorldModel", "{", "public", "static", "final", "int", "COW", "=", "16", ";", "public", "static", "final", "int", "CORRAL", "=", "32", ";", "public", "static", "final", "int", "ENEMY", "=", "64", ";", "public", "static", "final", "int", "TARGET", "=", "128", ";", "public", "static", "final", "int", "FORPLACE", "=", "256", ";", "public", "static", "final", "int", "ENEMYCORRAL", "=", "512", ";", "public", "static", "final", "int", "SWITCH", "=", "1024", ";", "public", "static", "final", "int", "OPEN_FENCE", "=", "2048", ";", "public", "static", "final", "int", "CLOSED_FENCE", "=", "4096", ";", "public", "static", "final", "int", "FENCE", "=", "OPEN_FENCE", "+", "CLOSED_FENCE", ";", "public", "static", "final", "int", "nbActions", "=", "8", ";", "public", "static", "final", "int", "agsByTeam", "=", "10", ";", "public", "int", "agPerceptionRatio", "=", "8", ";", "public", "static", "final", "int", "cowPerceptionRatio", "=", "4", ";", "double", "PSim", "=", "0.1", ";", "double", "PMax", "=", "0.5", ";", "Area", "corral", ";", "int", "cowsBlue", "=", "0", ";", "int", "cowsRed", "=", "0", ";", "int", "initialNbCows", "=", "0", ";", "int", "maxSteps", "=", "0", ";", "String", "opponent", ";", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "\"\"", "+", "WorldModel", ".", "class", ".", "getName", "(", ")", ")", ";", "public", "enum", "Move", "{", "north", ",", "south", ",", "east", ",", "west", ",", "northeast", ",", "southeast", ",", "northwest", ",", "southwest", ",", "skip", "}", ";", "public", "static", "WorldModel", "create", "(", "int", "w", ",", "int", "h", ",", "int", "nbAg", ")", "{", "return", "new", "WorldModel", "(", "w", ",", "h", ",", "nbAg", ")", ";", "}", "public", "WorldModel", "(", "int", "w", ",", "int", "h", ",", "int", "nbAg", ")", "{", "super", "(", "w", ",", "h", ",", "nbAg", ")", ";", "}", "public", "int", "getAgsByTeam", "(", ")", "{", "return", "agsByTeam", ";", "}", "private", "static", "final", "int", "OBS_FOR_NOT_FREE", "=", "ENEMY", "+", "AGENT", "+", "COW", "+", "CORRAL", "+", "ENEMYCORRAL", ";", "@", "Override", "public", "boolean", "isFree", "(", "int", "x", ",", "int", "y", ")", "{", "return", "super", ".", "isFree", "(", "x", ",", "y", ")", "&&", "!", "hasObject", "(", "OBS_FOR_NOT_FREE", ",", "x", ",", "y", ")", ";", "}", "public", "WorldView", "getView", "(", ")", "{", "return", "(", "WorldView", ")", "view", ";", "}", "public", "int", "getData", "(", "Location", "l", ")", "{", "return", "data", "[", "l", ".", "x", "]", "[", "l", ".", "y", "]", ";", "}", "public", "void", "setCorral", "(", "Location", "upperLeft", ",", "Location", "downRight", ")", "{", "for", "(", "int", "l", "=", "upperLeft", ".", "y", ";", "l", "<=", "downRight", ".", "y", ";", "l", "++", ")", "for", "(", "int", "c", "=", "upperLeft", ".", "x", ";", "c", "<=", "downRight", ".", "x", ";", "c", "++", ")", "{", "data", "[", "c", "]", "[", "l", "]", "=", "CORRAL", ";", "}", "corral", "=", "new", "Area", "(", "upperLeft", ",", "downRight", ")", ";", "}", "public", "Area", "getCorral", "(", ")", "{", "return", "corral", ";", "}", "public", "int", "getCowsBlue", "(", ")", "{", "return", "cowsBlue", ";", "}", "public", "int", "getCowsRed", "(", ")", "{", "return", "cowsRed", ";", "}", "public", "void", "setCowsBlue", "(", "int", "c", ")", "{", "cowsBlue", "=", "c", ";", "}", "public", "void", "setCowsRed", "(", "int", "c", ")", "{", "cowsRed", "=", "c", ";", "}", "public", "void", "setOpponent", "(", "String", "o", ")", "{", "opponent", "=", "o", ";", "}", "public", "String", "getOpponent", "(", ")", "{", "return", "opponent", ";", "}", "public", "void", "setPSim", "(", "double", "psim", ")", "{", "PSim", "=", "psim", ";", "}", "public", "void", "setPMax", "(", "double", "pmax", ")", "{", "PMax", "=", "pmax", ";", "}", "public", "void", "setMaxSteps", "(", "int", "s", ")", "{", "maxSteps", "=", "s", ";", "}", "public", "int", "getMaxSteps", "(", ")", "{", "return", "maxSteps", ";", "}", "public", "void", "setAgPerceptionRatio", "(", "int", "ratio", ")", "{", "agPerceptionRatio", "=", "ratio", ";", "}", "public", "int", "getAgPerceptionRatio", "(", ")", "{", "return", "agPerceptionRatio", ";", "}", "public", "void", "removeAll", "(", "int", "obj", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "width", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "height", ";", "j", "++", ")", "{", "if", "(", "hasObject", "(", "obj", ",", "i", ",", "j", ")", ")", "remove", "(", "obj", ",", "i", ",", "j", ")", ";", "}", "}", "}", "synchronized", "public", "boolean", "move", "(", "Move", "dir", ",", "int", "ag", ")", "throws", "Exception", "{", "if", "(", "ag", "<", "0", ")", "{", "logger", ".", "warning", "(", "\"\"", ")", ";", "return", "false", ";", "}", "Location", "l", "=", "getAgPos", "(", "ag", ")", ";", "if", "(", "l", "==", "null", ")", "{", "logger", ".", "warning", "(", "\"\"", "+", "(", "ag", "+", "1", ")", "+", "\"!\"", "+", "this", ")", ";", "return", "false", ";", "}", "Location", "n", "=", "null", ";", "switch", "(", "dir", ")", "{", "case", "north", ":", "n", "=", "new", "Location", "(", "l", ".", "x", ",", "l", ".", "y", "-", "1", ")", ";", "break", ";", "case", "south", ":", "n", "=", "new", "Location", "(", "l", ".", "x", ",", "l", ".", "y", "+", "1", ")", ";", "break", ";", "case", "east", ":", "n", "=", "new", "Location", "(", "l", ".", "x", "+", "1", ",", "l", ".", "y", ")", ";", "break", ";", "case", "west", ":", "n", "=", "new", "Location", "(", "l", ".", "x", "-", "1", ",", "l", ".", "y", ")", ";", "break", ";", "}", "if", "(", "n", "!=", "null", "&&", "canMoveTo", "(", "ag", ",", "n", ")", ")", "{", "if", "(", "!", "hasObject", "(", "AGENT", ",", "n", ")", "||", "move", "(", "dir", ",", "getAgAtPos", "(", "n", ")", ")", ")", "{", "setAgPos", "(", "ag", ",", "n", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}", "private", "boolean", "canMoveTo", "(", "int", "ag", ",", "Location", "l", ")", "{", "return", "isFreeOfObstacle", "(", "l", ")", ";", "}", "public", "void", "wall", "(", "int", "x1", ",", "int", "y1", ",", "int", "x2", ",", "int", "y2", ")", "{", "for", "(", "int", "i", "=", "x1", ";", "i", "<=", "x2", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "y1", ";", "j", "<=", "y2", ";", "j", "++", ")", "{", "add", "(", "OBSTACLE", ",", "i", ",", "j", ")", ";", ";", "}", "}", "}", "public", "String", "toString", "(", ")", "{", "StringBuilder", "s", "=", "new", "StringBuilder", "(", "\"|\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "{", "s", ".", "append", "(", "'-'", ")", ";", "}", "s", ".", "append", "(", "\"|n\"", ")", ";", "String", "bar", "=", "s", ".", "toString", "(", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "getHeight", "(", ")", ";", "j", "++", ")", "{", "s", ".", "append", "(", "'|'", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "getWidth", "(", ")", ";", "i", "++", ")", "{", "if", "(", "hasObject", "(", "OBSTACLE", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "'X'", ")", ";", "}", "else", "if", "(", "hasObject", "(", "AGENT", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "String", ".", "valueOf", "(", "getAgAtPos", "(", "i", ",", "j", ")", ")", ")", ";", "}", "else", "if", "(", "hasObject", "(", "COW", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "'c'", ")", ";", "}", "else", "if", "(", "hasObject", "(", "ENEMY", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "'E'", ")", ";", "}", "else", "if", "(", "hasObject", "(", "OPEN_FENCE", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "'f'", ")", ";", "}", "else", "if", "(", "hasObject", "(", "CLOSED_FENCE", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "'F'", ")", ";", "}", "else", "if", "(", "hasObject", "(", "SWITCH", ",", "i", ",", "j", ")", ")", "{", "s", ".", "append", "(", "'s'", ")", ";", "}", "else", "{", "s", ".", "append", "(", "'", "'", ")", ";", "}", "}", "s", ".", "append", "(", "\"|n\"", ")", ";", "}", "s", ".", "append", "(", "bar", ")", ";", "return", "s", ".", "toString", "(", ")", ";", "}", "public", "static", "Location", "getNewLocationForAction", "(", "Location", "pos", ",", "WorldModel", ".", "Move", "action", ")", "{", "switch", "(", "action", ")", "{", "case", "west", ":", "return", "new", "Location", "(", "pos", ".", "x", "-", "1", ",", "pos", ".", "y", ")", ";", "case", "east", ":", "return", "new", "Location", "(", "pos", ".", "x", "+", "1", ",", "pos", ".", "y", ")", ";", "case", "north", ":", "return", "new", "Location", "(", "pos", ".", "x", ",", "pos", ".", "y", "-", "1", ")", ";", "case", "northeast", ":", "return", "new", "Location", "(", "pos", ".", "x", "+", "1", ",", "pos", ".", "y", "-", "1", ")", ";", "case", "northwest", ":", "return", "new", "Location", "(", "pos", ".", "x", "-", "1", ",", "pos", ".", "y", "-", "1", ")", ";", "case", "south", ":", "return", "new", "Location", "(", "pos", ".", "x", ",", "pos", ".", "y", "+", "1", ")", ";", "case", "southeast", ":", "return", "new", "Location", "(", "pos", ".", "x", "+", "1", ",", "pos", ".", "y", "+", "1", ")", ";", "case", "southwest", ":", "return", "new", "Location", "(", "pos", ".", "x", "-", "1", ",", "pos", ".", "y", "+", "1", ")", ";", "}", "return", "null", ";", "}", "public", "static", "int", "stringToObject", "(", "String", "o", ")", "{", "if", "(", "o", ".", "equals", "(", "\"CLOSED_FENCE\"", ")", ")", "return", "CLOSED_FENCE", ";", "else", "if", "(", "o", ".", "equals", "(", "\"OPEN_FENCE\"", ")", ")", "return", "OPEN_FENCE", ";", "return", "-", "1", ";", "}", "}", "</s>" ]
9,156
[ "<s>", "package", "env", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "java", ".", "io", ".", "Serializable", ";", "public", "class", "Cow", "implements", "Serializable", "{", "private", "static", "final", "long", "serialVersionUID", "=", "3979318534857199194L", ";", "public", "int", "id", ";", "public", "int", "x", ",", "y", ";", "public", "int", "step", ";", "public", "int", "clId", ";", "public", "Cow", "(", "int", "id", ",", "int", "x", ",", "int", "y", ",", "int", "step", ")", "{", "this", ".", "id", "=", "id", ";", "this", ".", "x", "=", "x", ";", "this", ".", "y", "=", "y", ";", "this", ".", "step", "=", "step", ";", "this", ".", "clId", "=", "-", "1", ";", "}", "public", "Cow", "(", "int", "id", ",", "int", "x", ",", "int", "y", ")", "{", "this", "(", "id", ",", "x", ",", "y", ",", "0", ")", ";", "}", "}", "</s>" ]
9,157
[ "<s>", "package", "env", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "NoSuchElementException", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilder", ";", "import", "javax", ".", "xml", ".", "parsers", ".", "DocumentBuilderFactory", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Document", ";", "import", "org", ".", "w3c", ".", "dom", ".", "Element", ";", "import", "org", ".", "w3c", ".", "dom", ".", "NodeList", ";", "import", "org", ".", "xml", ".", "sax", ".", "SAXParseException", ";", "public", "class", "ACViewer", "extends", "Thread", "{", "private", "static", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "ACViewer", ".", "class", ".", "getName", "(", ")", ")", ";", "WorldModel", "model", "=", "null", ";", "WorldView", "view", "=", "null", ";", "DocumentBuilder", "builder", "=", "null", ";", "File", "massimServerBackupDir", ";", "public", "ACViewer", "(", "String", "massimBackDir", ",", "int", "w", ",", "int", "h", ")", "{", "massimServerBackupDir", "=", "new", "File", "(", "massimBackDir", ")", ";", "model", "=", "new", "WorldModel", "(", "w", ",", "h", ",", "WorldModel", ".", "agsByTeam", "*", "2", ")", ";", "view", "=", "new", "WorldView", "(", "\"\"", ",", "model", ")", ";", "model", ".", "setView", "(", "view", ")", ";", "}", "File", "getLastFile", "(", "File", "dir", ")", "{", "if", "(", "dir", "!=", "null", ")", "{", "File", "[", "]", "afiles", "=", "dir", ".", "listFiles", "(", ")", ";", "if", "(", "afiles", "!=", "null", "&&", "afiles", ".", "length", ">", "0", ")", "{", "List", "<", "File", ">", "lfiles", "=", "new", "ArrayList", "<", "File", ">", "(", ")", ";", "for", "(", "File", "f", ":", "dir", ".", "listFiles", "(", ")", ")", "{", "lfiles", ".", "add", "(", "f", ")", ";", "}", "return", "Collections", ".", "max", "(", "lfiles", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"no", "files", "in", "\"", "+", "dir", ")", ";", "}", "}", "return", "null", ";", "}", "void", "updateWorld", "(", "File", "f", ")", "throws", "Exception", "{", "if", "(", "builder", "==", "null", ")", "{", "builder", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ".", "newDocumentBuilder", "(", ")", ";", "}", "Document", "doc", "=", "builder", ".", "parse", "(", "f", ")", ";", "Element", "simulation", "=", "(", "Element", ")", "doc", ".", "getElementsByTagName", "(", "\"simulation\"", ")", ".", "item", "(", "0", ")", ";", "view", ".", "setCycle", "(", "Integer", ".", "parseInt", "(", "simulation", ".", "getAttribute", "(", "\"\"", ")", ")", ")", ";", "Element", "team", "=", "(", "Element", ")", "simulation", ".", "getElementsByTagName", "(", "\"team1\"", ")", ".", "item", "(", "0", ")", ";", "model", ".", "setCowsBlue", "(", "Integer", ".", "parseInt", "(", "team", ".", "getAttribute", "(", "\"score\"", ")", ")", ")", ";", "team", "=", "(", "Element", ")", "simulation", ".", "getElementsByTagName", "(", "\"team2\"", ")", ".", "item", "(", "0", ")", ";", "model", ".", "setCowsRed", "(", "Integer", ".", "parseInt", "(", "team", ".", "getAttribute", "(", "\"score\"", ")", ")", ")", ";", "clearModel", "(", ")", ";", "NodeList", "cows", "=", "simulation", ".", "getElementsByTagName", "(", "\"cow\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "cows", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Element", "cow", "=", "(", "Element", ")", "cows", ".", "item", "(", "i", ")", ";", "int", "x", "=", "Integer", ".", "parseInt", "(", "cow", ".", "getAttribute", "(", "\"posX\"", ")", ")", ";", "int", "y", "=", "Integer", ".", "parseInt", "(", "cow", ".", "getAttribute", "(", "\"posY\"", ")", ")", ";", "model", ".", "add", "(", "WorldModel", ".", "COW", ",", "x", ",", "y", ")", ";", "}", "NodeList", "ags", "=", "simulation", ".", "getElementsByTagName", "(", "\"agent\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ags", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Element", "ag", "=", "(", "Element", ")", "ags", ".", "item", "(", "i", ")", ";", "int", "x", "=", "Integer", ".", "parseInt", "(", "ag", ".", "getAttribute", "(", "\"posX\"", ")", ")", ";", "int", "y", "=", "Integer", ".", "parseInt", "(", "ag", ".", "getAttribute", "(", "\"posY\"", ")", ")", ";", "if", "(", "ag", ".", "getAttribute", "(", "\"team\"", ")", ".", "equals", "(", "\"participant\"", ")", ")", "{", "model", ".", "add", "(", "WorldModel", ".", "AGENT", ",", "x", ",", "y", ")", ";", "}", "else", "{", "model", ".", "add", "(", "WorldModel", ".", "ENEMY", ",", "x", ",", "y", ")", ";", "}", "}", "}", "void", "clearModel", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "model", ".", "getWidth", "(", ")", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "model", ".", "getHeight", "(", ")", ";", "j", "++", ")", "{", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "AGENT", ",", "i", ",", "j", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "COW", ",", "i", ",", "j", ")", "||", "model", ".", "hasObject", "(", "WorldModel", ".", "ENEMY", ",", "i", ",", "j", ")", ")", "{", "model", ".", "set", "(", "WorldModel", ".", "CLEAN", ",", "i", ",", "j", ")", ";", "}", "}", "}", "}", "public", "void", "addObject", "(", "int", "object", ",", "int", "x", ",", "int", "y", ")", "{", "model", ".", "add", "(", "object", ",", "x", ",", "y", ")", ";", "}", "public", "WorldModel", "getModel", "(", ")", "{", "return", "model", ";", "}", "public", "void", "finish", "(", ")", "{", "view", ".", "dispose", "(", ")", ";", "this", ".", "interrupt", "(", ")", ";", "}", "public", "void", "run", "(", ")", "{", "while", "(", "true", ")", "{", "try", "{", "sleep", "(", "500", ")", ";", "File", "lastFile", "=", "getLastFile", "(", "getLastFile", "(", "massimServerBackupDir", ")", ")", ";", "if", "(", "lastFile", "!=", "null", ")", "{", "logger", ".", "info", "(", "\"\"", "+", "lastFile", ")", ";", "updateWorld", "(", "lastFile", ")", ";", "}", "}", "catch", "(", "InterruptedException", "e", ")", "{", "return", ";", "}", "catch", "(", "NoSuchElementException", "e", ")", "{", "}", "catch", "(", "SAXParseException", "e", ")", "{", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "new", "ACViewer", "(", "\"\"", ",", "70", ",", "70", ")", ".", "start", "(", ")", ";", "}", "}", "</s>" ]
9,158
[ "<s>", "package", "env", ";", "import", "jia", ".", "Vec", ";", "import", "java", ".", "util", ".", "Map", ";", "public", "interface", "IClusterModel", "{", "public", "void", "setCows", "(", "Cow", "[", "]", "c", ",", "int", "H", ",", "int", "W", ")", ";", "public", "void", "update", "(", ")", ";", "public", "int", "[", "]", "getAlloc", "(", ")", ";", "public", "Vec", "[", "]", "getCenters", "(", ")", ";", "public", "int", "[", "]", "[", "]", "getData", "(", ")", ";", "public", "int", "[", "]", "getMap", "(", ")", ";", "public", "int", "[", "]", "getMaxDist", "(", ")", ";", "public", "int", "getNumberOfCluster", "(", ")", ";", "public", "int", "[", "]", "getNumCows", "(", ")", ";", "public", "void", "insertTree", "(", "int", "x", ",", "int", "y", ")", ";", "public", "void", "setStepcl", "(", "int", "step", ")", ";", "public", "void", "changeClusterer", "(", "int", "clusterer", ")", ";", "public", "void", "changeMaxDist", "(", "int", "a", ")", ";", "public", "void", "changeWCprop", "(", "int", "radius", ",", "int", "nCows", ")", ";", "public", "int", "getPrefRadius", "(", ")", ";", "public", "int", "getPrefNCows", "(", ")", ";", "public", "void", "changePTCprop", "(", "int", "k", ")", ";", "public", "double", "getPrefkPTC", "(", ")", ";", "}", "</s>" ]
9,159
[ "<s>", "package", "env", ";", "public", "class", "ClusterModelFactory", "{", "static", "private", "IClusterModel", "clModel", ";", "static", "public", "boolean", "centralized", "=", "true", ";", "private", "static", "String", "end", "=", "\"\"", ";", "private", "static", "String", "wpsName", "=", "\"clustermodel\"", ";", "private", "static", "String", "cartagoRole", "=", "\"cowboy\"", ";", "private", "static", "String", "artName", "=", "\"clModel\"", ";", "private", "static", "ClusterModel", "clModelC", "=", "null", ";", "public", "static", "IClusterModel", "getModel", "(", "String", "agName", ")", "{", "if", "(", "centralized", ")", "{", "synchronized", "(", "ClusterModelFactory", ".", "class", ")", "{", "if", "(", "clModel", "==", "null", ")", "return", "clModel", "=", "new", "ClusterModel", "(", ")", ";", "else", "return", "clModel", ";", "}", "}", "else", "{", "try", "{", "Thread", ".", "sleep", "(", "3", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "new", "CClusterModel", "(", "end", ",", "wpsName", ",", "cartagoRole", ",", "artName", ",", "agName", "+", "\"Cl\"", "+", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "}", "}", "public", "static", "ClusterModel", "getModelCent", "(", ")", "{", "synchronized", "(", "ClusterModelFactory", ".", "class", ")", "{", "if", "(", "clModelC", "==", "null", ")", "return", "clModelC", "=", "new", "ClusterModel", "(", ")", ";", "else", "return", "clModelC", ";", "}", "}", "}", "</s>" ]
9,160
[ "<s>", "package", "env", ";", "import", "jason", ".", "environment", ".", "grid", ".", "GridWorldView", ";", "import", "java", ".", "awt", ".", "BorderLayout", ";", "import", "java", ".", "awt", ".", "Color", ";", "import", "java", ".", "awt", ".", "FlowLayout", ";", "import", "java", ".", "awt", ".", "Graphics", ";", "import", "java", ".", "awt", ".", "event", ".", "MouseEvent", ";", "import", "java", ".", "awt", ".", "event", ".", "MouseMotionListener", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "javax", ".", "swing", ".", "BorderFactory", ";", "import", "javax", ".", "swing", ".", "BoxLayout", ";", "import", "javax", ".", "swing", ".", "JLabel", ";", "import", "javax", ".", "swing", ".", "JPanel", ";", "public", "class", "WorldView", "extends", "GridWorldView", "{", "private", "static", "final", "long", "serialVersionUID", "=", "1L", ";", "JLabel", "jCycle", ";", "JLabel", "jCowsC", ";", "JLabel", "jlMouseLoc", ";", "IClusterModel", "Cl", "=", "ClusterModelFactory", ".", "getModel", "(", "\"WorldView\"", ")", ";", "ICowModel", "Cm", "=", "CowModelFactory", ".", "getModel", "(", "\"WorldView\"", ")", ";", "public", "void", "destroy", "(", ")", "{", "setVisible", "(", "false", ")", ";", "}", "public", "WorldView", "(", "WorldModel", "model", ",", "int", "windowSize", ")", "{", "this", "(", "\"\"", ",", "model", ",", "windowSize", ")", ";", "}", "public", "WorldView", "(", "String", "title", ",", "WorldModel", "model", ")", "{", "this", "(", "title", ",", "model", ",", "800", ")", ";", "}", "public", "WorldView", "(", "String", "title", ",", "WorldModel", "model", ",", "int", "windowSize", ")", "{", "super", "(", "model", ",", "title", ",", "windowSize", ")", ";", "setVisible", "(", "true", ")", ";", "repaint", "(", ")", ";", "}", "@", "Override", "public", "void", "initComponents", "(", "int", "width", ")", "{", "super", ".", "initComponents", "(", "width", ")", ";", "JPanel", "args", "=", "new", "JPanel", "(", ")", ";", "args", ".", "setLayout", "(", "new", "BoxLayout", "(", "args", ",", "BoxLayout", ".", "Y_AXIS", ")", ")", ";", "JPanel", "msg", "=", "new", "JPanel", "(", ")", ";", "msg", ".", "setLayout", "(", "new", "BoxLayout", "(", "msg", ",", "BoxLayout", ".", "Y_AXIS", ")", ")", ";", "msg", ".", "setBorder", "(", "BorderFactory", ".", "createEtchedBorder", "(", ")", ")", ";", "JPanel", "pmoise", "=", "new", "JPanel", "(", "new", "FlowLayout", "(", "FlowLayout", ".", "CENTER", ")", ")", ";", "jlMouseLoc", "=", "new", "JLabel", "(", "\"0,0\"", ")", ";", "pmoise", ".", "add", "(", "jlMouseLoc", ")", ";", "pmoise", ".", "setBorder", "(", "BorderFactory", ".", "createEtchedBorder", "(", ")", ")", ";", "JPanel", "p", "=", "new", "JPanel", "(", "new", "FlowLayout", "(", "FlowLayout", ".", "CENTER", ")", ")", ";", "p", ".", "add", "(", "new", "JLabel", "(", "\"Cycle:\"", ")", ")", ";", "jCycle", "=", "new", "JLabel", "(", "\"0\"", ")", ";", "p", ".", "add", "(", "jCycle", ")", ";", "p", ".", "add", "(", "new", "JLabel", "(", "\"\"", ")", ")", ";", "jCowsC", "=", "new", "JLabel", "(", "\"0\"", ")", ";", "p", ".", "add", "(", "jCowsC", ")", ";", "msg", ".", "add", "(", "p", ")", ";", "JPanel", "s", "=", "new", "JPanel", "(", "new", "BorderLayout", "(", ")", ")", ";", "s", ".", "add", "(", "BorderLayout", ".", "WEST", ",", "args", ")", ";", "s", ".", "add", "(", "BorderLayout", ".", "CENTER", ",", "msg", ")", ";", "s", ".", "add", "(", "BorderLayout", ".", "EAST", ",", "pmoise", ")", ";", "getContentPane", "(", ")", ".", "add", "(", "BorderLayout", ".", "SOUTH", ",", "s", ")", ";", "getCanvas", "(", ")", ".", "addMouseMotionListener", "(", "new", "MouseMotionListener", "(", ")", "{", "public", "void", "mouseDragged", "(", "MouseEvent", "e", ")", "{", "}", "public", "void", "mouseMoved", "(", "MouseEvent", "e", ")", "{", "int", "col", "=", "e", ".", "getX", "(", ")", "/", "cellSizeW", ";", "int", "lin", "=", "e", ".", "getY", "(", ")", "/", "cellSizeH", ";", "if", "(", "col", ">=", "0", "&&", "lin", ">=", "0", "&&", "col", "<", "getModel", "(", ")", ".", "getWidth", "(", ")", "&&", "lin", "<", "getModel", "(", ")", ".", "getHeight", "(", ")", ")", "{", "String", "desc", ";", "desc", "=", "\"\"", "+", "col", "+", "\",\"", "+", "lin", ";", "int", "ag", "=", "model", ".", "getAgAtPos", "(", "col", ",", "lin", ")", ";", "if", "(", "ag", "++", ">=", "0", ")", "desc", "=", "\"Agent", "\"", "+", "ag", "+", "\";", "\"", "+", "desc", ";", "jlMouseLoc", ".", "setText", "(", "desc", ")", ";", "}", "}", "}", ")", ";", "}", "public", "void", "setCycle", "(", "int", "c", ")", "{", "Cm", ".", "updateCows", "(", ")", ";", "if", "(", "jCycle", "!=", "null", ")", "{", "WorldModel", "wm", "=", "(", "WorldModel", ")", "model", ";", "String", "steps", "=", "\"\"", ";", "if", "(", "wm", ".", "getMaxSteps", "(", ")", ">", "0", ")", "{", "steps", "=", "\"/\"", "+", "wm", ".", "getMaxSteps", "(", ")", ";", "}", "jCycle", ".", "setText", "(", "c", "+", "steps", ")", ";", "jCowsC", ".", "setText", "(", "wm", ".", "getCowsBlue", "(", ")", "+", "\"", "x", "\"", "+", "wm", ".", "getCowsRed", "(", ")", ")", ";", "}", "}", "@", "Override", "public", "void", "draw", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ",", "int", "object", ")", "{", "switch", "(", "object", ")", "{", "case", "WorldModel", ".", "CORRAL", ":", "drawCorral", "(", "g", ",", "x", ",", "y", ")", ";", "break", ";", "case", "WorldModel", ".", "COW", ":", "drawCow", "(", "g", ",", "x", ",", "y", ")", ";", "break", ";", "case", "WorldModel", ".", "ENEMY", ":", "drawEnemy", "(", "g", ",", "x", ",", "y", ")", ";", "break", ";", "case", "WorldModel", ".", "TARGET", ":", "drawTarget", "(", "g", ",", "x", ",", "y", ")", ";", "break", ";", "case", "WorldModel", ".", "FORPLACE", ":", "drawFormPlace", "(", "g", ",", "x", ",", "y", ")", ";", "break", ";", "case", "WorldModel", ".", "SWITCH", ":", "drawSwhitch", "(", "g", ",", "x", ",", "y", ")", ";", "break", ";", "case", "WorldModel", ".", "OPEN_FENCE", ":", "drawFence", "(", "g", ",", "x", ",", "y", ",", "false", ")", ";", "break", ";", "case", "WorldModel", ".", "CLOSED_FENCE", ":", "drawFence", "(", "g", ",", "x", ",", "y", ",", "true", ")", ";", "break", ";", "}", "}", "@", "Override", "public", "void", "drawAgent", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ",", "Color", "c", ",", "int", "id", ")", "{", "g", ".", "setColor", "(", "c", ")", ";", "g", ".", "fillOval", "(", "x", "*", "cellSizeW", "+", "2", ",", "y", "*", "cellSizeH", "+", "2", ",", "cellSizeW", "-", "4", ",", "cellSizeH", "-", "4", ")", ";", "}", "public", "void", "drawCorral", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ")", "{", "g", ".", "setColor", "(", "Color", ".", "gray", ")", ";", "g", ".", "fillRect", "(", "x", "*", "cellSizeW", ",", "y", "*", "cellSizeH", ",", "cellSizeW", ",", "cellSizeH", ")", ";", "g", ".", "setColor", "(", "Color", ".", "pink", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "2", ",", "y", "*", "cellSizeH", "+", "2", ",", "cellSizeW", "-", "4", ",", "cellSizeH", "-", "4", ")", ";", "g", ".", "drawLine", "(", "x", "*", "cellSizeW", "+", "2", ",", "y", "*", "cellSizeH", "+", "2", ",", "(", "x", "+", "1", ")", "*", "cellSizeW", "-", "2", ",", "(", "y", "+", "1", ")", "*", "cellSizeH", "-", "2", ")", ";", "g", ".", "drawLine", "(", "x", "*", "cellSizeW", "+", "2", ",", "(", "y", "+", "1", ")", "*", "cellSizeH", "-", "2", ",", "(", "x", "+", "1", ")", "*", "cellSizeW", "-", "2", ",", "y", "*", "cellSizeH", "+", "2", ")", ";", "}", "public", "void", "drawTarget", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ")", "{", "g", ".", "setColor", "(", "Color", ".", "darkGray", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "2", ",", "y", "*", "cellSizeH", "+", "2", ",", "cellSizeW", "-", "4", ",", "cellSizeH", "-", "4", ")", ";", "g", ".", "setColor", "(", "Color", ".", "white", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "3", ",", "y", "*", "cellSizeH", "+", "3", ",", "cellSizeW", "-", "6", ",", "cellSizeH", "-", "6", ")", ";", "g", ".", "setColor", "(", "Color", ".", "darkGray", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "4", ",", "y", "*", "cellSizeH", "+", "4", ",", "cellSizeW", "-", "8", ",", "cellSizeH", "-", "8", ")", ";", "}", "public", "void", "drawFormPlace", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ")", "{", "g", ".", "setColor", "(", "Color", ".", "green", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "2", ",", "y", "*", "cellSizeH", "+", "2", ",", "cellSizeW", "-", "4", ",", "cellSizeH", "-", "4", ")", ";", "g", ".", "setColor", "(", "Color", ".", "lightGray", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "3", ",", "y", "*", "cellSizeH", "+", "3", ",", "cellSizeW", "-", "6", ",", "cellSizeH", "-", "6", ")", ";", "g", ".", "setColor", "(", "Color", ".", "gray", ")", ";", "g", ".", "drawRect", "(", "x", "*", "cellSizeW", "+", "4", ",", "y", "*", "cellSizeH", "+", "4", ",", "cellSizeW", "-", "8", ",", "cellSizeH", "-", "8", ")", ";", "}", "public", "void", "drawCow", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ")", "{", "int", "[", "]", "alloc", "=", "Cl", ".", "getMap", "(", ")", ";", "Cow", "[", "]", "c", "=", "Cm", ".", "getCows", "(", ")", ";", "int", "id", "=", "-", "1", ";", "Color", "[", "]", "C", "=", "new", "Color", "[", "6", "]", ";", "C", "[", "0", "]", "=", "Color", ".", "green", ";", "C", "[", "1", "]", "=", "Color", ".", "yellow", ";", "C", "[", "2", "]", "=", "Color", ".", "gray", ";", "C", "[", "3", "]", "=", "Color", ".", "white", ";", "C", "[", "4", "]", "=", "Color", ".", "blue", ";", "C", "[", "5", "]", "=", "Color", ".", "cyan", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "c", ".", "length", ";", "i", "++", ")", "{", "if", "(", "c", "[", "i", "]", "==", "null", ")", "{", "continue", ";", "}", "if", "(", "x", "==", "c", "[", "i", "]", ".", "x", "&&", "y", "==", "c", "[", "i", "]", ".", "y", ")", "{", "id", "=", "c", "[", "i", "]", ".", "id", ";", "break", ";", "}", "}", "int", "tmp", ";", "if", "(", "id", "!=", "-", "1", ")", "{", "tmp", "=", "alloc", "[", "id", "]", ";", "}", "else", "{", "tmp", "=", "-", "1", ";", "}", "id", "=", "(", "int", ")", "tmp", ";", "if", "(", "id", "<", "0", "||", "id", ">", "4", ")", "{", "id", "=", "5", ";", "}", "g", ".", "setColor", "(", "C", "[", "id", "]", ")", ";", "g", ".", "fillRect", "(", "x", "*", "cellSizeW", "+", "1", ",", "y", "*", "cellSizeH", "+", "1", ",", "cellSizeW", "-", "1", ",", "cellSizeH", "-", "1", ")", ";", "}", "public", "void", "drawEnemy", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ")", "{", "int", "gw", "=", "1", ";", "g", ".", "setColor", "(", "Color", ".", "red", ")", ";", "g", ".", "fillOval", "(", "x", "*", "cellSizeW", "+", "gw", ",", "y", "*", "cellSizeH", "+", "gw", ",", "cellSizeW", "-", "gw", "*", "2", ",", "cellSizeH", "-", "gw", "*", "2", ")", ";", "}", "private", "void", "drawFence", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ",", "boolean", "closed", ")", "{", "g", ".", "setColor", "(", "Color", ".", "yellow", ")", ";", "g", ".", "fillRect", "(", "x", "*", "cellSizeW", ",", "y", "*", "cellSizeH", ",", "cellSizeW", ",", "cellSizeH", ")", ";", "if", "(", "closed", ")", "{", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "x", ",", "y", ")", ")", "g", ".", "setColor", "(", "Color", ".", "black", ")", ";", "else", "g", ".", "setColor", "(", "Color", ".", "red", ")", ";", "g", ".", "drawLine", "(", "x", "*", "cellSizeW", "+", "2", ",", "y", "*", "cellSizeH", "+", "2", ",", "(", "x", "+", "1", ")", "*", "cellSizeW", "-", "2", ",", "(", "y", "+", "1", ")", "*", "cellSizeH", "-", "2", ")", ";", "g", ".", "drawLine", "(", "x", "*", "cellSizeW", "+", "2", ",", "(", "y", "+", "1", ")", "*", "cellSizeH", "-", "2", ",", "(", "x", "+", "1", ")", "*", "cellSizeW", "-", "2", ",", "y", "*", "cellSizeH", "+", "2", ")", ";", "}", "else", "{", "if", "(", "model", ".", "hasObject", "(", "WorldModel", ".", "OBSTACLE", ",", "x", ",", "y", ")", ")", "g", ".", "setColor", "(", "Color", ".", "black", ")", ";", "else", "g", ".", "setColor", "(", "Color", ".", "green", ")", ";", "g", ".", "drawLine", "(", "x", "*", "cellSizeW", "+", "2", ",", "(", "y", "*", "cellSizeH", ")", "+", "(", "cellSizeH", "/", "2", ")", ",", "(", "x", "+", "1", ")", "*", "cellSizeW", "-", "2", ",", "(", "y", "*", "cellSizeH", ")", "+", "(", "cellSizeH", "/", "2", ")", ")", ";", "}", "}", "private", "void", "drawSwhitch", "(", "Graphics", "g", ",", "int", "x", ",", "int", "y", ")", "{", "g", ".", "setColor", "(", "Color", ".", "yellow", ")", ";", "g", ".", "fillRect", "(", "x", "*", "cellSizeW", ",", "y", "*", "cellSizeH", ",", "cellSizeW", ",", "cellSizeH", ")", ";", "g", ".", "setColor", "(", "Color", ".", "black", ")", ";", "g", ".", "drawLine", "(", "x", "*", "cellSizeW", "+", "2", ",", "(", "y", "+", "1", ")", "*", "cellSizeH", "-", "2", ",", "(", "x", "+", "1", ")", "*", "cellSizeW", "-", "2", ",", "y", "*", "cellSizeH", "+", "2", ")", ";", "}", "}", "</s>" ]
9,161
[ "<s>", "package", "env", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Vector", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "alice", ".", "cartago", ".", "ArtifactId", ";", "import", "alice", ".", "cartago", ".", "CartagoException", ";", "import", "alice", ".", "cartago", ".", "CartagoService", ";", "import", "alice", ".", "cartago", ".", "ICartagoContext", ";", "import", "alice", ".", "cartago", ".", "Op", ";", "import", "alice", ".", "cartago", ".", "security", ".", "UserCredential", ";", "import", "alice", ".", "cartago", ".", "security", ".", "UserIdCredential", ";", "import", "jia", ".", "Vec", ";", "public", "class", "CClusterModel", "implements", "IClusterModel", ",", "Runnable", "{", "private", "Logger", "logger", "=", "Logger", ".", "getLogger", "(", "ClusterModel", ".", "class", ".", "getName", "(", ")", ")", ";", "private", "UserCredential", "cred", ";", "private", "ICartagoContext", "cWps", ";", "private", "ArtifactId", "cArt", ";", "private", "String", "end", ";", "private", "String", "wpsName", ";", "private", "String", "cartagoRole", ";", "private", "String", "artName", ";", "private", "static", "class", "buffer", "{", "public", "int", "actStep", "=", "-", "1", ";", "public", "int", "clStep", ";", "public", "int", "[", "]", "alloc", ";", "public", "Vec", "[", "]", "Centers", ";", "public", "int", "[", "]", "[", "]", "data", ";", "public", "int", "[", "]", "map", "=", "new", "int", "[", "1000", "]", ";", "public", "int", "[", "]", "maxDist", ";", "public", "int", "[", "]", "numCows", ";", "public", "int", "numberOfCows", ";", "public", "int", "prefNCows", ";", "public", "int", "prefRadius", ";", "public", "double", "prefkPTC", ";", "public", "ICowModel", "cowModel", "=", "CowModelFactory", ".", "getModel", "(", "\"\"", ")", ";", "}", "public", "static", "buffer", "bf", "=", "new", "buffer", "(", ")", ";", "public", "void", "update", "(", ")", "{", "this", ".", "run", "(", ")", ";", "try", "{", "int", "i", "=", "0", ";", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"update\"", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "alloc", "=", "(", "int", "[", "]", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"clusterAlloc\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "Centers", "=", "(", "Vec", "[", "]", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "data", "=", "(", "int", "[", "]", "[", "]", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"clusterData\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "map", "=", "(", "int", "[", "]", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"clusterMap\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "maxDist", "=", "(", "int", "[", "]", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "numCows", "=", "(", "int", "[", "]", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "numberOfCows", "=", "(", "Integer", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "prefNCows", "=", "(", "Integer", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "prefRadius", "=", "(", "Integer", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "bf", ".", "prefkPTC", "=", "(", "Double", ")", "cWps", ".", "observeProperty", "(", "cArt", ",", "\"\"", ")", ".", "getValue", "(", ")", ";", "logger", ".", "info", "(", "\"HHHJ\"", "+", "(", "i", "++", ")", ")", ";", "logger", ".", "info", "(", "\"HHHJ", "\"", "+", "bf", ".", "prefkPTC", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "CClusterModel", "(", "String", "end", ",", "String", "wpsName", ",", "String", "cartagoRole", ",", "String", "artName", ",", "String", "agName", ")", "{", "this", ".", "end", "=", "end", ";", "this", ".", "wpsName", "=", "wpsName", ";", "this", ".", "cartagoRole", "=", "cartagoRole", ";", "this", ".", "artName", "=", "artName", ";", "cred", "=", "new", "UserIdCredential", "(", "agName", ")", ";", "try", "{", "cWps", "=", "CartagoService", ".", "joinWorkspace", "(", "this", ".", "wpsName", ",", "this", ".", "end", ",", "this", ".", "cartagoRole", ",", "cred", ")", ";", "cArt", "=", "cWps", ".", "lookupArtifact", "(", "this", ".", "artName", ",", "-", "1", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "severe", "(", "\"\"", "+", "e", ")", ";", "}", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"init\"", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "int", "[", "]", "getAlloc", "(", ")", "{", "return", "bf", ".", "alloc", ";", "}", "public", "Vec", "[", "]", "getCenters", "(", ")", "{", "return", "bf", ".", "Centers", ";", "}", "public", "int", "[", "]", "[", "]", "getData", "(", ")", "{", "return", "bf", ".", "data", ";", "}", "public", "int", "[", "]", "getMap", "(", ")", "{", "return", "bf", ".", "map", ".", "clone", "(", ")", ";", "}", "public", "int", "[", "]", "getMaxDist", "(", ")", "{", "return", "bf", ".", "maxDist", ";", "}", "public", "int", "[", "]", "getNumCows", "(", ")", "{", "return", "bf", ".", "numCows", ";", "}", "public", "int", "getNumberOfCluster", "(", ")", "{", "return", "bf", ".", "numberOfCows", ";", "}", "public", "synchronized", "void", "insertTree", "(", "int", "x", ",", "int", "y", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ",", "x", ",", "y", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "void", "setStepcl", "(", "int", "step", ")", "{", "if", "(", "step", ">", "bf", ".", "clStep", ")", "bf", ".", "clStep", "=", "step", ";", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ",", "step", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "void", "run", "(", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ",", "bf", ".", "cowModel", ".", "getCows", "(", ")", ",", "bf", ".", "cowModel", ".", "getSizeh", "(", ")", ",", "bf", ".", "cowModel", ".", "getSizew", "(", ")", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "if", "(", "bf", ".", "actStep", "<", "bf", ".", "clStep", ")", "{", "bf", ".", "actStep", "=", "bf", ".", "clStep", ";", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"clusterRun\"", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "update", "(", ")", ";", "}", "}", "public", "void", "changeClusterer", "(", "int", "a", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ",", "a", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "void", "changeMaxDist", "(", "int", "a", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ",", "a", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "void", "changePTCprop", "(", "int", "k", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"clusterPTCP\"", ",", "k", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "void", "changeWCprop", "(", "int", "radius", ",", "int", "nCows", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"clusterWCP\"", ",", "radius", ",", "nCows", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "public", "int", "getPrefNCows", "(", ")", "{", "return", "bf", ".", "prefNCows", ";", "}", "public", "int", "getPrefRadius", "(", ")", "{", "return", "bf", ".", "prefRadius", ";", "}", "public", "double", "getPrefkPTC", "(", ")", "{", "return", "bf", ".", "prefkPTC", ";", "}", "public", "void", "setCows", "(", "Cow", "[", "]", "c", ",", "int", "H", ",", "int", "W", ")", "{", "try", "{", "cWps", ".", "use", "(", "null", ",", "cArt", ",", "new", "Op", "(", "\"\"", ",", "c", ",", "H", ",", "W", ")", ",", "null", ",", "null", ",", "-", "1", ")", ";", "}", "catch", "(", "CartagoException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "</s>" ]
9,162
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "action", ";", "import", "java", ".", "util", ".", "List", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "User", ";", "import", "org", ".", "jboss", ".", "weld", ".", "environment", ".", "se", ".", "Weld", ";", "import", "org", ".", "jboss", ".", "weld", ".", "environment", ".", "se", ".", "WeldContainer", ";", "import", "org", ".", "junit", ".", "Test", ";", "public", "class", "UserManagerTest", "{", "@", "Test", "public", "void", "testUserCreation", "(", ")", "{", "final", "Weld", "weld", "=", "new", "Weld", "(", ")", ";", "WeldContainer", "weldContainer", "=", "weld", ".", "initialize", "(", ")", ";", "final", "UserManager", "userManager", "=", "weldContainer", ".", "instance", "(", ")", ".", "select", "(", "UserManager", ".", "class", ")", ".", "get", "(", ")", ";", "userManager", ".", "createNewUsers", "(", ")", ";", "weld", ".", "shutdown", "(", ")", ";", "}", "@", "Test", "public", "void", "testQueries", "(", ")", "{", "final", "Weld", "weld", "=", "new", "Weld", "(", ")", ";", "WeldContainer", "weldContainer", "=", "weld", ".", "initialize", "(", ")", ";", "final", "UserManager", "userManager", "=", "weldContainer", ".", "instance", "(", ")", ".", "select", "(", "UserManager", ".", "class", ")", ".", "get", "(", ")", ";", "final", "List", "<", "?", ">", "users", "=", "userManager", ".", "getUsersBetween30And40", "(", ")", ";", "for", "(", "Object", "o", ":", "users", ")", "{", "System", ".", "err", ".", "println", "(", "o", ".", "toString", "(", ")", ")", ";", "}", "weld", ".", "shutdown", "(", ")", ";", "}", "@", "Test", "public", "void", "testAvgQuery", "(", ")", "{", "final", "Weld", "weld", "=", "new", "Weld", "(", ")", ";", "WeldContainer", "weldContainer", "=", "weld", ".", "initialize", "(", ")", ";", "final", "UserManager", "userManager", "=", "weldContainer", ".", "instance", "(", ")", ".", "select", "(", "UserManager", ".", "class", ")", ".", "get", "(", ")", ";", "userManager", ".", "displayAvgCreditByGender", "(", ")", ";", "weld", ".", "shutdown", "(", ")", ";", "}", "}", "</s>" ]
9,163
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Disposes", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Produces", ";", "import", "javax", ".", "inject", ".", "Singleton", ";", "import", "javax", ".", "persistence", ".", "EntityManagerFactory", ";", "import", "javax", ".", "persistence", ".", "Persistence", ";", "public", "class", "EMFProvider", "{", "@", "Produces", "@", "Singleton", "public", "EntityManagerFactory", "createEMF", "(", ")", "{", "return", "Persistence", ".", "createEntityManagerFactory", "(", "\"users\"", ")", ";", "}", "public", "void", "close", "(", "@", "Disposes", "EntityManagerFactory", "factory", ")", "{", "factory", ".", "close", "(", ")", ";", "}", "}", "</s>" ]
9,164
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Retention", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Target", ";", "import", "javax", ".", "interceptor", ".", "InterceptorBinding", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "*", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "RetentionPolicy", ".", "*", ";", "@", "InterceptorBinding", "@", "Target", "(", "{", "METHOD", ",", "TYPE", "}", ")", "@", "Retention", "(", "RUNTIME", ")", "public", "@", "interface", "Transactional", "{", "}", "</s>" ]
9,165
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "enterprise", ".", "context", ".", "Dependent", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Produces", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "inject", ".", "Singleton", ";", "import", "javax", ".", "persistence", ".", "EntityManager", ";", "import", "javax", ".", "persistence", ".", "EntityManagerFactory", ";", "@", "Singleton", "public", "class", "TransactionManager", "{", "@", "Inject", "private", "EntityManagerFactory", "factory", ";", "private", "ThreadLocal", "<", "EntityManager", ">", "emHolder", "=", "new", "ThreadLocal", "<", "EntityManager", ">", "(", ")", ";", "public", "void", "begin", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "entityManager", "=", "factory", ".", "createEntityManager", "(", ")", ";", "entityManager", ".", "getTransaction", "(", ")", ".", "begin", "(", ")", ";", "emHolder", ".", "set", "(", "entityManager", ")", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "}", "@", "Produces", "@", "Dependent", "public", "EntityManager", "getEntityManager", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "else", "{", "return", "entityManager", ";", "}", "}", "public", "void", "commit", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "else", "{", "entityManager", ".", "getTransaction", "(", ")", ".", "commit", "(", ")", ";", "entityManager", ".", "close", "(", ")", ";", "emHolder", ".", "set", "(", "null", ")", ";", "}", "}", "public", "void", "rollback", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "else", "{", "entityManager", ".", "getTransaction", "(", ")", ".", "rollback", "(", ")", ";", "entityManager", ".", "close", "(", ")", ";", "emHolder", ".", "set", "(", "null", ")", ";", "}", "}", "}", "</s>" ]
9,166
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "interceptor", ".", "AroundInvoke", ";", "import", "javax", ".", "interceptor", ".", "Interceptor", ";", "import", "javax", ".", "interceptor", ".", "InvocationContext", ";", "@", "Transactional", "@", "Interceptor", "public", "class", "TransactionInterceptor", "{", "@", "Inject", "TransactionManager", "manager", ";", "@", "AroundInvoke", "public", "Object", "manageTransaction", "(", "InvocationContext", "ctx", ")", "throws", "Exception", "{", "manager", ".", "begin", "(", ")", ";", "try", "{", "final", "Object", "result", "=", "ctx", ".", "proceed", "(", ")", ";", "manager", ".", "commit", "(", ")", ";", "return", "result", ";", "}", "catch", "(", "Exception", "e", ")", "{", "manager", ".", "rollback", "(", ")", ";", "throw", "e", ";", "}", "}", "}", "</s>" ]
9,167
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "javax", ".", "persistence", ".", "Entity", ";", "import", "javax", ".", "persistence", ".", "GeneratedValue", ";", "import", "javax", ".", "persistence", ".", "Id", ";", "import", "javax", ".", "persistence", ".", "ManyToOne", ";", "@", "Entity", "public", "class", "Address", "{", "public", "Address", "(", ")", "{", "}", "public", "Address", "(", "String", "street", ",", "String", "city", ",", "String", "zipCode", ",", "User", "owner", ")", "{", "this", ".", "street", "=", "street", ";", "this", ".", "city", "=", "city", ";", "this", ".", "zipCode", "=", "zipCode", ";", "this", ".", "owner", "=", "owner", ";", "owner", ".", "getAddresses", "(", ")", ".", "add", "(", "this", ")", ";", "}", "@", "Id", "@", "GeneratedValue", "public", "Long", "getId", "(", ")", "{", "return", "id", ";", "}", "public", "void", "setId", "(", "Long", "id", ")", "{", "this", ".", "id", "=", "id", ";", "}", "private", "Long", "id", ";", "public", "String", "getStreet", "(", ")", "{", "return", "street", ";", "}", "public", "void", "setStreet", "(", "String", "street", ")", "{", "this", ".", "street", "=", "street", ";", "}", "private", "String", "street", ";", "public", "String", "getCity", "(", ")", "{", "return", "city", ";", "}", "public", "void", "setCity", "(", "String", "city", ")", "{", "this", ".", "city", "=", "city", ";", "}", "private", "String", "city", ";", "public", "String", "getZipCode", "(", ")", "{", "return", "zipCode", ";", "}", "public", "void", "setZipCode", "(", "String", "zipCode", ")", "{", "this", ".", "zipCode", "=", "zipCode", ";", "}", "private", "String", "zipCode", ";", "@", "ManyToOne", "public", "User", "getOwner", "(", ")", "{", "return", "owner", ";", "}", "public", "void", "setOwner", "(", "User", "owner", ")", "{", "this", ".", "owner", "=", "owner", ";", "}", "private", "User", "owner", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"Address\"", ")", ";", "sb", ".", "append", "(", "\"{id=\"", ")", ".", "append", "(", "id", ")", ";", "sb", ".", "append", "(", "\",", "street='\"", ")", ".", "append", "(", "street", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "city='\"", ")", ".", "append", "(", "city", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "zipCode='\"", ")", ".", "append", "(", "zipCode", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "'}'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
9,168
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "public", "enum", "Gender", "{", "MALE", ",", "FEMALE", ",", "NOT_SURE", "}", "</s>" ]
9,169
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "javax", ".", "persistence", ".", "Embeddable", ";", "@", "Embeddable", "public", "class", "Login", "{", "public", "Login", "(", ")", "{", "}", "public", "Login", "(", "String", "username", ",", "String", "password", ")", "{", "this", ".", "username", "=", "username", ";", "this", ".", "password", "=", "password", ";", "}", "public", "String", "getUsername", "(", ")", "{", "return", "username", ";", "}", "public", "void", "setUsername", "(", "String", "username", ")", "{", "this", ".", "username", "=", "username", ";", "}", "private", "String", "username", ";", "public", "String", "getPassword", "(", ")", "{", "return", "password", ";", "}", "public", "void", "setPassword", "(", "String", "password", ")", "{", "this", ".", "password", "=", "password", ";", "}", "private", "String", "password", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"Login\"", ")", ";", "sb", ".", "append", "(", "\"{username='\"", ")", ".", "append", "(", "username", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "password='\"", ")", ".", "append", "(", "password", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "'}'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
9,170
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "javax", ".", "persistence", ".", "CascadeType", ";", "import", "javax", ".", "persistence", ".", "Entity", ";", "import", "javax", ".", "persistence", ".", "EnumType", ";", "import", "javax", ".", "persistence", ".", "Enumerated", ";", "import", "javax", ".", "persistence", ".", "GeneratedValue", ";", "import", "javax", ".", "persistence", ".", "Id", ";", "import", "javax", ".", "persistence", ".", "OneToMany", ";", "import", "javax", ".", "persistence", ".", "Persistence", ";", "import", "javax", ".", "persistence", ".", "Temporal", ";", "import", "javax", ".", "persistence", ".", "TemporalType", ";", "@", "Entity", "public", "class", "User", "{", "public", "User", "(", ")", "{", "}", "public", "User", "(", "String", "firstName", ",", "String", "lastName", ",", "Date", "birthDate", ",", "Gender", "gender", ",", "int", "credits", ",", "String", "username", ",", "String", "password", ")", "{", "this", ".", "firstName", "=", "firstName", ";", "this", ".", "lastName", "=", "lastName", ";", "this", ".", "birthDate", "=", "birthDate", ";", "this", ".", "gender", "=", "gender", ";", "this", ".", "credits", "=", "credits", ";", "this", ".", "login", "=", "new", "Login", "(", "username", ",", "password", ")", ";", "}", "@", "Id", "@", "GeneratedValue", "public", "Long", "getId", "(", ")", "{", "return", "id", ";", "}", "public", "void", "setId", "(", "Long", "id", ")", "{", "this", ".", "id", "=", "id", ";", "}", "private", "Long", "id", ";", "public", "String", "getFirstName", "(", ")", "{", "return", "firstName", ";", "}", "public", "void", "setFirstName", "(", "String", "firstName", ")", "{", "this", ".", "firstName", "=", "firstName", ";", "}", "private", "String", "firstName", ";", "public", "String", "getLastName", "(", ")", "{", "return", "lastName", ";", "}", "public", "void", "setLastName", "(", "String", "lastName", ")", "{", "this", ".", "lastName", "=", "lastName", ";", "}", "private", "String", "lastName", ";", "@", "OneToMany", "(", "cascade", "=", "CascadeType", ".", "PERSIST", ",", "mappedBy", "=", "\"owner\"", ")", "public", "Set", "<", "Address", ">", "getAddresses", "(", ")", "{", "return", "addresses", ";", "}", "public", "void", "setAddresses", "(", "Set", "<", "Address", ">", "addresses", ")", "{", "this", ".", "addresses", "=", "addresses", ";", "}", "private", "Set", "<", "Address", ">", "addresses", "=", "new", "HashSet", "<", "Address", ">", "(", ")", ";", "@", "Temporal", "(", "TemporalType", ".", "DATE", ")", "public", "Date", "getBirthDate", "(", ")", "{", "return", "birthDate", ";", "}", "public", "void", "setBirthDate", "(", "Date", "birthDate", ")", "{", "this", ".", "birthDate", "=", "birthDate", ";", "}", "private", "Date", "birthDate", ";", "@", "Enumerated", "(", "EnumType", ".", "STRING", ")", "public", "Gender", "getGender", "(", ")", "{", "return", "gender", ";", "}", "public", "void", "setGender", "(", "Gender", "gender", ")", "{", "this", ".", "gender", "=", "gender", ";", "}", "private", "Gender", "gender", ";", "public", "int", "getCredits", "(", ")", "{", "return", "credits", ";", "}", "public", "void", "setCredits", "(", "int", "credits", ")", "{", "this", ".", "credits", "=", "credits", ";", "}", "private", "int", "credits", ";", "public", "Login", "getLogin", "(", ")", "{", "return", "login", ";", "}", "public", "void", "setLogin", "(", "Login", "login", ")", "{", "this", ".", "login", "=", "login", ";", "}", "private", "Login", "login", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"User\"", ")", ";", "sb", ".", "append", "(", "\"{id=\"", ")", ".", "append", "(", "id", ")", ";", "sb", ".", "append", "(", "\"\"", ")", ".", "append", "(", "firstName", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "lastName='\"", ")", ".", "append", "(", "lastName", ")", ".", "append", "(", "'\\''", ")", ";", "if", "(", "Persistence", ".", "getPersistenceUtil", "(", ")", ".", "isLoaded", "(", "this", ",", "\"addresses\"", ")", ")", "{", "sb", ".", "append", "(", "\",", "addresses=\"", ")", ".", "append", "(", "addresses", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "\",", "addresses=\"", ")", ".", "append", "(", "\"lazy\"", ")", ";", "}", "sb", ".", "append", "(", "\",", "birthDate=\"", ")", ".", "append", "(", "birthDate", ")", ";", "sb", ".", "append", "(", "\",", "gender=\"", ")", ".", "append", "(", "gender", ")", ";", "sb", ".", "append", "(", "\",", "credits=\"", ")", ".", "append", "(", "credits", ")", ";", "sb", ".", "append", "(", "\",", "login=\"", ")", ".", "append", "(", "login", ")", ";", "sb", ".", "append", "(", "'}'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
9,171
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "action", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Calendar", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Random", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "inject", ".", "Provider", ";", "import", "javax", ".", "persistence", ".", "EntityManager", ";", "import", "javax", ".", "persistence", ".", "EntityManagerFactory", ";", "import", "javax", ".", "persistence", ".", "Tuple", ";", "import", "javax", ".", "persistence", ".", "TypedQuery", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "CriteriaBuilder", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "CriteriaQuery", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "Fetch", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "Path", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "Root", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "Selection", ";", "import", "javax", ".", "persistence", ".", "criteria", ".", "SetJoin", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Address", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Address_", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Gender", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Login_", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "User", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "User_", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ".", "Transactional", ";", "@", "Transactional", "public", "class", "UserManager", "{", "@", "Inject", "EntityManagerFactory", "factory", ";", "private", "Random", "random", "=", "new", "Random", "(", ")", ";", "@", "Inject", "Provider", "<", "EntityManager", ">", "lazyEM", ";", "@", "Transactional", "public", "List", "<", "User", ">", "getUsersNamedEmmanuel", "(", ")", "{", "EntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "CriteriaBuilder", "cb", "=", "em", ".", "getCriteriaBuilder", "(", ")", ";", "final", "CriteriaQuery", "<", "User", ">", "query", "=", "cb", ".", "createQuery", "(", "User", ".", "class", ")", ";", "final", "Root", "<", "User", ">", "u", "=", "query", ".", "from", "(", "User", ".", "class", ")", ";", "u", ".", "fetch", "(", "User_", ".", "addresses", ")", ";", "query", ".", "select", "(", "u", ")", ".", "distinct", "(", "true", ")", ".", "where", "(", "cb", ".", "equal", "(", "u", ".", "get", "(", "User_", ".", "firstName", ")", ",", "\"Emmanuel\"", ")", ")", ";", "final", "TypedQuery", "<", "User", ">", "typedQuery", "=", "em", ".", "createQuery", "(", "query", ")", ";", "typedQuery", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "20", ")", ";", "final", "List", "<", "User", ">", "resultList", "=", "typedQuery", ".", "getResultList", "(", ")", ";", "return", "resultList", ";", "}", "@", "Transactional", "public", "List", "<", "User", ">", "getUsersFromParis", "(", ")", "{", "EntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "CriteriaBuilder", "cb", "=", "em", ".", "getCriteriaBuilder", "(", ")", ";", "final", "CriteriaQuery", "<", "User", ">", "query", "=", "cb", ".", "createQuery", "(", "User", ".", "class", ")", ";", "final", "Root", "<", "User", ">", "u", "=", "query", ".", "from", "(", "User", ".", "class", ")", ";", "final", "SetJoin", "<", "User", ",", "Address", ">", "a", "=", "u", ".", "join", "(", "User_", ".", "addresses", ")", ";", "u", ".", "fetch", "(", "User_", ".", "addresses", ")", ";", "query", ".", "select", "(", "u", ")", ".", "distinct", "(", "true", ")", ".", "where", "(", "cb", ".", "equal", "(", "a", ".", "get", "(", "Address_", ".", "city", ")", ",", "\"Paris\"", ")", ")", ";", "final", "TypedQuery", "<", "User", ">", "typedQuery", "=", "em", ".", "createQuery", "(", "query", ")", ";", "typedQuery", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "20", ")", ";", "final", "List", "<", "User", ">", "resultList", "=", "typedQuery", ".", "getResultList", "(", ")", ";", "return", "resultList", ";", "}", "@", "Transactional", "public", "List", "<", "User", ">", "getUsersBetween30And40", "(", ")", "{", "EntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "CriteriaBuilder", "cb", "=", "em", ".", "getCriteriaBuilder", "(", ")", ";", "final", "CriteriaQuery", "<", "User", ">", "query", "=", "cb", ".", "createQuery", "(", "User", ".", "class", ")", ";", "final", "Root", "<", "User", ">", "u", "=", "query", ".", "from", "(", "User", ".", "class", ")", ";", "final", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal", ".", "setTimeInMillis", "(", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "cal", ".", "add", "(", "Calendar", ".", "YEAR", ",", "-", "30", ")", ";", "Date", "end", "=", "new", "Date", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ";", "cal", ".", "add", "(", "Calendar", ".", "YEAR", ",", "-", "10", ")", ";", "Date", "begin", "=", "new", "Date", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ";", "query", ".", "select", "(", "u", ")", ".", "where", "(", "cb", ".", "between", "(", "u", ".", "get", "(", "User_", ".", "birthDate", ")", ",", "begin", ",", "end", ")", ")", ";", "final", "TypedQuery", "<", "User", ">", "typedQuery", "=", "em", ".", "createQuery", "(", "query", ")", ";", "typedQuery", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "20", ")", ";", "final", "List", "<", "User", ">", "resultList", "=", "typedQuery", ".", "getResultList", "(", ")", ";", "return", "resultList", ";", "}", "@", "Transactional", "public", "void", "displayAvgCreditByGender", "(", ")", "{", "EntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "CriteriaBuilder", "cb", "=", "em", ".", "getCriteriaBuilder", "(", ")", ";", "final", "CriteriaQuery", "<", "Tuple", ">", "query", "=", "cb", ".", "createTupleQuery", "(", ")", ";", "final", "Root", "<", "User", ">", "u", "=", "query", ".", "from", "(", "User", ".", "class", ")", ";", "final", "Path", "<", "Gender", ">", "gender", "=", "u", ".", "get", "(", "User_", ".", "gender", ")", ";", "gender", ".", "alias", "(", "\"gender\"", ")", ";", "final", "Selection", "<", "Double", ">", "credits", "=", "cb", ".", "avg", "(", "u", ".", "get", "(", "User_", ".", "credits", ")", ")", ".", "alias", "(", "\"credits\"", ")", ";", "query", ".", "multiselect", "(", "credits", ",", "gender", ",", "cb", ".", "count", "(", "u", ")", ".", "alias", "(", "\"nbr\"", ")", ")", ".", "groupBy", "(", "gender", ")", ".", "having", "(", "cb", ".", "in", "(", "gender", ")", ".", "value", "(", "Gender", ".", "FEMALE", ")", ".", "value", "(", "Gender", ".", "MALE", ")", ")", ".", "orderBy", "(", "cb", ".", "desc", "(", "gender", ")", ")", ";", "final", "TypedQuery", "<", "Tuple", ">", "typedQuery", "=", "em", ".", "createQuery", "(", "query", ")", ";", "typedQuery", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "20", ")", ";", "final", "List", "<", "Tuple", ">", "list", "=", "typedQuery", ".", "getResultList", "(", ")", ";", "for", "(", "Tuple", "tuple", ":", "list", ")", "{", "final", "Double", "average", "=", "tuple", ".", "get", "(", "credits", ")", ";", "System", ".", "err", ".", "println", "(", "\"Avg", "credit", "\"", "+", "tuple", ".", "get", "(", "credits", ")", "+", "\"", "\"", "+", "tuple", ".", "get", "(", "\"gender\"", ")", "+", "\"", "found", "\"", "+", "tuple", ".", "get", "(", "\"nbr\"", ")", "+", "\"", "times\"", ")", ";", "}", "}", "@", "Transactional", "public", "void", "createNewUsers", "(", ")", "{", "final", "EntityManager", "entityManager", "=", "lazyEM", ".", "get", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "1000", ";", "i", "++", ")", "{", "entityManager", ".", "persist", "(", "createNewRandomUser", "(", ")", ")", ";", "}", "}", "private", "User", "createNewRandomUser", "(", ")", "{", "final", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal", ".", "set", "(", "19", "*", "100", "+", "50", "+", "random", ".", "nextInt", "(", "60", ")", ",", "random", ".", "nextInt", "(", "12", ")", ",", "random", ".", "nextInt", "(", "28", ")", ")", ";", "final", "int", "userRand", "=", "random", ".", "nextInt", "(", ")", ";", "User", "user", "=", "new", "User", "(", "userRand", "%", "20", "==", "0", "?", "\"Emmanuel\"", ":", "\"Daniel\"", "+", "userRand", ",", "\"Marie\"", "+", "random", ".", "nextInt", "(", ")", ",", "new", "Date", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ",", "getGender", "(", ")", ",", "random", ".", "nextInt", "(", "30", ")", ",", "\"user\"", "+", "random", ".", "nextInt", "(", ")", ",", "\"\"", "+", "random", ".", "nextInt", "(", ")", ")", ";", "new", "Address", "(", "random", ".", "nextInt", "(", ")", "+", "\"\"", "+", "random", ".", "nextInt", "(", ")", ",", "city", ".", "get", "(", "random", ".", "nextInt", "(", "city", ".", "size", "(", ")", ")", ")", ",", "new", "Integer", "(", "random", ".", "nextInt", "(", ")", "%", "9999", ")", ".", "toString", "(", ")", ",", "user", ")", ";", "new", "Address", "(", "random", ".", "nextInt", "(", ")", "+", "\"\"", "+", "random", ".", "nextInt", "(", ")", ",", "city", ".", "get", "(", "random", ".", "nextInt", "(", "city", ".", "size", "(", ")", ")", ")", ",", "new", "Integer", "(", "random", ".", "nextInt", "(", ")", "%", "9999", ")", ".", "toString", "(", ")", ",", "user", ")", ";", "new", "Address", "(", "random", ".", "nextInt", "(", ")", "+", "\"\"", "+", "random", ".", "nextInt", "(", ")", ",", "city", ".", "get", "(", "random", ".", "nextInt", "(", "city", ".", "size", "(", ")", ")", ")", ",", "new", "Integer", "(", "random", ".", "nextInt", "(", ")", "%", "9999", ")", ".", "toString", "(", ")", ",", "user", ")", ";", "return", "user", ";", "}", "private", "Gender", "getGender", "(", ")", "{", "int", "i", "=", "random", ".", "nextInt", "(", "10", ")", ";", "if", "(", "i", "<", "4", ")", "{", "return", "Gender", ".", "MALE", ";", "}", "else", "if", "(", "i", "<", "8", ")", "{", "return", "Gender", ".", "FEMALE", ";", "}", "else", "{", "return", "Gender", ".", "NOT_SURE", ";", "}", "}", "private", "List", "<", "String", ">", "city", "=", "new", "ArrayList", "<", "String", ">", "(", "10", ")", ";", "public", "UserManager", "(", ")", "{", "city", ".", "add", "(", "\"Paris\"", ")", ";", "city", ".", "add", "(", "\"New", "York\"", ")", ";", "city", ".", "add", "(", "\"Sidney\"", ")", ";", "city", ".", "add", "(", "\"Anwerpen\"", ")", ";", "city", ".", "add", "(", "\"Atlanta\"", ")", ";", "}", "}", "</s>" ]
9,172
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "action", ";", "import", "org", ".", "jboss", ".", "weld", ".", "environment", ".", "se", ".", "Weld", ";", "import", "org", ".", "jboss", ".", "weld", ".", "environment", ".", "se", ".", "WeldContainer", ";", "import", "org", ".", "junit", ".", "Test", ";", "public", "class", "BookManagerTest", "{", "@", "Test", "public", "void", "testQuery", "(", ")", "{", "final", "Weld", "weld", "=", "new", "Weld", "(", ")", ";", "WeldContainer", "weldContainer", "=", "weld", ".", "initialize", "(", ")", ";", "final", "BookManager", "userManager", "=", "weldContainer", ".", "instance", "(", ")", ".", "select", "(", "BookManager", ".", "class", ")", ".", "get", "(", ")", ";", "userManager", ".", "getAllBooksWhoseAuthorIsEmmanuel", "(", ")", ";", "weld", ".", "shutdown", "(", ")", ";", "}", "@", "Test", "public", "void", "testUserCreation", "(", ")", "{", "final", "Weld", "weld", "=", "new", "Weld", "(", ")", ";", "WeldContainer", "weldContainer", "=", "weld", ".", "initialize", "(", ")", ";", "final", "BookManager", "userManager", "=", "weldContainer", ".", "instance", "(", ")", ".", "select", "(", "BookManager", ".", "class", ")", ".", "get", "(", ")", ";", "userManager", ".", "createNewUsers", "(", ")", ";", "weld", ".", "shutdown", "(", ")", ";", "}", "}", "</s>" ]
9,173
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "action", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Calendar", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Random", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "inject", ".", "Provider", ";", "import", "javax", ".", "persistence", ".", "EntityManager", ";", "import", "javax", ".", "persistence", ".", "EntityManagerFactory", ";", "import", "org", ".", "apache", ".", "lucene", ".", "search", ".", "Query", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Address", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Book", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "Gender", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ".", "User", ";", "import", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ".", "Transactional", ";", "import", "org", ".", "hibernate", ".", "CacheMode", ";", "import", "org", ".", "hibernate", ".", "Session", ";", "import", "org", ".", "hibernate", ".", "search", ".", "Search", ";", "import", "org", ".", "hibernate", ".", "search", ".", "jpa", ".", "FullTextEntityManager", ";", "import", "org", ".", "hibernate", ".", "search", ".", "jpa", ".", "FullTextQuery", ";", "import", "org", ".", "hibernate", ".", "search", ".", "query", ".", "dsl", ".", "QueryBuilder", ";", "@", "Transactional", "public", "class", "BookManager", "{", "private", "Random", "random", "=", "new", "Random", "(", ")", ";", "@", "Inject", "Provider", "<", "FullTextEntityManager", ">", "lazyEM", ";", "public", "void", "getAllBooksFrom1977", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "Calendar", "pubDate", "=", "Calendar", ".", "getInstance", "(", ")", ";", "pubDate", ".", "set", "(", "1977", ",", "0", ",", "01", ")", ";", "Date", "begin", "=", "new", "Date", "(", "pubDate", ".", "getTimeInMillis", "(", ")", ")", ";", "pubDate", ".", "set", "(", "1977", ",", "11", ",", "31", ")", ";", "Date", "end", "=", "new", "Date", "(", "pubDate", ".", "getTimeInMillis", "(", ")", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "range", "(", ")", ".", "onField", "(", "\"\"", ")", ".", "from", "(", "begin", ")", ".", "to", "(", "end", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "public", "void", "getAllBooksStrictlyAbove1000Pages", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "range", "(", ")", ".", "onField", "(", "\"\"", ")", ".", "above", "(", "1000", ")", ".", "excludeLimit", "(", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "public", "void", "getAllBooksWhoseAuthorIsEmmanuel", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "keyword", "(", ")", ".", "onField", "(", "\"\"", ")", ".", "matching", "(", "\"Emmanuel\"", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "public", "void", "getAllBooksWhoseAuthorIsNotEmmanuel", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "all", "(", ")", ".", "except", "(", "builder", ".", "keyword", "(", ")", ".", "onField", "(", "\"\"", ")", ".", "matching", "(", "\"Emmanuel\"", ")", ".", "createQuery", "(", ")", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "public", "void", "getAllBooksOnPlantsAndHands", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "bool", "(", ")", ".", "should", "(", "builder", ".", "keyword", "(", ")", ".", "onField", "(", "\"title\"", ")", ".", "boostedTo", "(", "4f", ")", ".", "andField", "(", "\"description\"", ")", ".", "matching", "(", "\"plants\"", ")", ".", "createQuery", "(", ")", ")", ".", "should", "(", "builder", ".", "keyword", "(", ")", ".", "onField", "(", "\"title\"", ")", ".", "boostedTo", "(", "4f", ")", ".", "andField", "(", "\"description\"", ")", ".", "matching", "(", "\"hands\"", ")", ".", "createQuery", "(", ")", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "public", "void", "getAllBooksOnPlentsAndHends", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "bool", "(", ")", ".", "should", "(", "builder", ".", "keyword", "(", ")", ".", "onField", "(", "\"title_ngram\"", ")", ".", "boostedTo", "(", "4f", ")", ".", "andField", "(", "\"\"", ")", ".", "matching", "(", "\"plents\"", ")", ".", "createQuery", "(", ")", ")", ".", "should", "(", "builder", ".", "keyword", "(", ")", ".", "onField", "(", "\"title_ngram\"", ")", ".", "boostedTo", "(", "4f", ")", ".", "andField", "(", "\"\"", ")", ".", "matching", "(", "\"hends\"", ")", ".", "createQuery", "(", ")", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "public", "void", "getAllBooksStarred5InTheLast10Years", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "final", "QueryBuilder", "builder", "=", "em", ".", "getSearchFactory", "(", ")", ".", "buildQueryBuilder", "(", ")", ".", "forEntity", "(", "Book", ".", "class", ")", ".", "get", "(", ")", ";", "final", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal", ".", "setTimeInMillis", "(", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "cal", ".", "add", "(", "Calendar", ".", "YEAR", ",", "-", "10", ")", ";", "final", "Query", "luceneQuery", "=", "builder", ".", "bool", "(", ")", ".", "must", "(", "builder", ".", "range", "(", ")", ".", "onField", "(", "\"starred\"", ")", ".", "above", "(", "5", ")", ".", "createQuery", "(", ")", ")", ".", "must", "(", "builder", ".", "range", "(", ")", ".", "onField", "(", "\"\"", ")", ".", "above", "(", "new", "Date", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ")", ".", "createQuery", "(", ")", ")", ".", "createQuery", "(", ")", ";", "System", ".", "out", ".", "println", "(", "luceneQuery", ".", "toString", "(", ")", ")", ";", "final", "FullTextQuery", "query", "=", "em", ".", "createFullTextQuery", "(", "luceneQuery", ",", "Book", ".", "class", ")", ";", "final", "List", "<", "Book", ">", "resultList", "=", "query", ".", "setFirstResult", "(", "0", ")", ".", "setMaxResults", "(", "5", ")", ".", "getResultList", "(", ")", ";", "displayListOfBooks", "(", "resultList", ",", "query", ")", ";", "}", "private", "void", "displayListOfBooks", "(", "List", "<", "Book", ">", "resultList", ",", "FullTextQuery", "query", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", "+", "query", ".", "getResultSize", "(", ")", ")", ";", "for", "(", "Book", "book", ":", "resultList", ")", "{", "System", ".", "out", ".", "println", "(", "book", ".", "toString", "(", ")", ")", ";", "}", "}", "@", "Transactional", "public", "void", "createNewUsers", "(", ")", "{", "final", "EntityManager", "entityManager", "=", "lazyEM", ".", "get", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "1000", ";", "i", "++", ")", "{", "entityManager", ".", "persist", "(", "createNewRandomBook", "(", ")", ")", ";", "}", "}", "private", "Book", "createNewRandomBook", "(", ")", "{", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal", ".", "set", "(", "19", "*", "100", "+", "50", "+", "random", ".", "nextInt", "(", "60", ")", ",", "random", ".", "nextInt", "(", "12", ")", ",", "random", ".", "nextInt", "(", "28", ")", ")", ";", "User", "user", "=", "new", "User", "(", "firstname", ".", "get", "(", "random", ".", "nextInt", "(", "firstname", ".", "size", "(", ")", ")", ")", ",", "\"Marie\"", "+", "random", ".", "nextInt", "(", ")", ",", "new", "Date", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ",", "getGender", "(", ")", ",", "random", ".", "nextInt", "(", "30", ")", ",", "\"user\"", "+", "random", ".", "nextInt", "(", ")", ",", "\"\"", "+", "random", ".", "nextInt", "(", ")", ")", ";", "new", "Address", "(", "random", ".", "nextInt", "(", ")", "+", "\"\"", "+", "random", ".", "nextInt", "(", ")", ",", "city", ".", "get", "(", "random", ".", "nextInt", "(", "city", ".", "size", "(", ")", ")", ")", ",", "new", "Integer", "(", "random", ".", "nextInt", "(", ")", "%", "9999", ")", ".", "toString", "(", ")", ",", "user", ")", ";", "new", "Address", "(", "random", ".", "nextInt", "(", ")", "+", "\"\"", "+", "random", ".", "nextInt", "(", ")", ",", "city", ".", "get", "(", "random", ".", "nextInt", "(", "city", ".", "size", "(", ")", ")", ")", ",", "new", "Integer", "(", "random", ".", "nextInt", "(", ")", "%", "9999", ")", ".", "toString", "(", ")", ",", "user", ")", ";", "new", "Address", "(", "random", ".", "nextInt", "(", ")", "+", "\"\"", "+", "random", ".", "nextInt", "(", ")", ",", "city", ".", "get", "(", "random", ".", "nextInt", "(", "city", ".", "size", "(", ")", ")", ")", ",", "new", "Integer", "(", "random", ".", "nextInt", "(", ")", "%", "9999", ")", ".", "toString", "(", ")", ",", "user", ")", ";", "Book", "book", "=", "new", "Book", "(", ")", ";", "book", ".", "setAuthor", "(", "user", ")", ";", "book", ".", "setDescription", "(", "description", ".", "get", "(", "random", ".", "nextInt", "(", "description", ".", "size", "(", ")", ")", ")", ")", ";", "book", ".", "setTitle", "(", "title", ".", "get", "(", "random", ".", "nextInt", "(", "title", ".", "size", "(", ")", ")", ")", ")", ";", "cal", ".", "add", "(", "Calendar", ".", "YEAR", ",", "random", ".", "nextInt", "(", "60", ")", ")", ";", "book", ".", "setPublicationDate", "(", "new", "Date", "(", "cal", ".", "getTimeInMillis", "(", ")", ")", ")", ";", "book", ".", "setNumberOfPages", "(", "random", ".", "nextInt", "(", "1000", ")", "+", "30", ")", ";", "book", ".", "setStarred", "(", "random", ".", "nextInt", "(", "5", ")", "+", "1", ")", ";", "return", "book", ";", "}", "private", "Gender", "getGender", "(", ")", "{", "int", "i", "=", "random", ".", "nextInt", "(", "10", ")", ";", "if", "(", "i", "<", "4", ")", "{", "return", "Gender", ".", "MALE", ";", "}", "else", "if", "(", "i", "<", "8", ")", "{", "return", "Gender", ".", "FEMALE", ";", "}", "else", "{", "return", "Gender", ".", "NOT_SURE", ";", "}", "}", "private", "List", "<", "String", ">", "city", "=", "new", "ArrayList", "<", "String", ">", "(", "10", ")", ";", "private", "List", "<", "String", ">", "description", "=", "new", "ArrayList", "<", "String", ">", "(", "10", ")", ";", "private", "List", "<", "String", ">", "title", "=", "new", "ArrayList", "<", "String", ">", "(", "10", ")", ";", "private", "List", "<", "String", ">", "firstname", "=", "new", "ArrayList", "<", "String", ">", "(", "20", ")", ";", "public", "BookManager", "(", ")", "{", "city", ".", "add", "(", "\"Paris\"", ")", ";", "city", ".", "add", "(", "\"New", "York\"", ")", ";", "city", ".", "add", "(", "\"Sidney\"", ")", ";", "city", ".", "add", "(", "\"Anwerpen\"", ")", ";", "city", ".", "add", "(", "\"Atlanta\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "title", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", "+", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", "+", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "description", ".", "add", "(", "\"\"", ")", ";", "firstname", ".", "add", "(", "\"Jacob\"", ")", ";", "firstname", ".", "add", "(", "\"Ethan\"", ")", ";", "firstname", ".", "add", "(", "\"Michael\"", ")", ";", "firstname", ".", "add", "(", "\"Alexander\"", ")", ";", "firstname", ".", "add", "(", "\"William\"", ")", ";", "firstname", ".", "add", "(", "\"Joshua\"", ")", ";", "firstname", ".", "add", "(", "\"Daniel\"", ")", ";", "firstname", ".", "add", "(", "\"Jayden\"", ")", ";", "firstname", ".", "add", "(", "\"Noah\"", ")", ";", "firstname", ".", "add", "(", "\"Anthony\"", ")", ";", "firstname", ".", "add", "(", "\"Isabella\"", ")", ";", "firstname", ".", "add", "(", "\"Emma\"", ")", ";", "firstname", ".", "add", "(", "\"Olivia\"", ")", ";", "firstname", ".", "add", "(", "\"Sophia\"", ")", ";", "firstname", ".", "add", "(", "\"Ava\"", ")", ";", "firstname", ".", "add", "(", "\"Emily\"", ")", ";", "firstname", ".", "add", "(", "\"Madison\"", ")", ";", "firstname", ".", "add", "(", "\"Abigail\"", ")", ";", "firstname", ".", "add", "(", "\"Chloe\"", ")", ";", "firstname", ".", "add", "(", "\"Mia\"", ")", ";", "firstname", ".", "add", "(", "\"Emmanuel\"", ")", ";", "}", "public", "void", "reindexBooks", "(", ")", "{", "FullTextEntityManager", "em", "=", "lazyEM", ".", "get", "(", ")", ";", "try", "{", "em", ".", "createIndexer", "(", "Book", ".", "class", ")", ".", "batchSizeToLoadObjects", "(", "100", ")", ".", "cacheMode", "(", "CacheMode", ".", "IGNORE", ")", ".", "optimizeAfterPurge", "(", "true", ")", ".", "optimizeOnFinish", "(", "true", ")", ".", "purgeAllOnStart", "(", "true", ")", ".", "threadsToLoadObjects", "(", "5", ")", ".", "threadsForSubsequentFetching", "(", "5", ")", ".", "startAndWait", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "}", "}", "}", "</s>" ]
9,174
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "interceptor", ".", "AroundInvoke", ";", "import", "javax", ".", "interceptor", ".", "Interceptor", ";", "import", "javax", ".", "interceptor", ".", "InvocationContext", ";", "@", "Transactional", "@", "Interceptor", "public", "class", "TransactionInterceptor", "{", "@", "Inject", "TransactionManager", "manager", ";", "@", "AroundInvoke", "public", "Object", "manageTransaction", "(", "InvocationContext", "ctx", ")", "throws", "Exception", "{", "manager", ".", "begin", "(", ")", ";", "try", "{", "final", "Object", "result", "=", "ctx", ".", "proceed", "(", ")", ";", "manager", ".", "commit", "(", ")", ";", "return", "result", ";", "}", "catch", "(", "Exception", "e", ")", "{", "manager", ".", "rollback", "(", ")", ";", "throw", "e", ";", "}", "}", "}", "</s>" ]
9,175
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "enterprise", ".", "context", ".", "Dependent", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Produces", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "inject", ".", "Singleton", ";", "import", "javax", ".", "persistence", ".", "EntityManager", ";", "import", "javax", ".", "persistence", ".", "EntityManagerFactory", ";", "@", "Singleton", "public", "class", "TransactionManager", "{", "@", "Inject", "private", "EntityManagerFactory", "factory", ";", "private", "ThreadLocal", "<", "EntityManager", ">", "emHolder", "=", "new", "ThreadLocal", "<", "EntityManager", ">", "(", ")", ";", "public", "void", "begin", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "entityManager", "=", "factory", ".", "createEntityManager", "(", ")", ";", "entityManager", ".", "getTransaction", "(", ")", ".", "begin", "(", ")", ";", "emHolder", ".", "set", "(", "entityManager", ")", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "}", "@", "Produces", "@", "Dependent", "public", "EntityManager", "getEntityManager", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "else", "{", "return", "entityManager", ";", "}", "}", "public", "void", "commit", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "else", "{", "entityManager", ".", "getTransaction", "(", ")", ".", "commit", "(", ")", ";", "entityManager", ".", "close", "(", ")", ";", "emHolder", ".", "set", "(", "null", ")", ";", "}", "}", "public", "void", "rollback", "(", ")", "{", "EntityManager", "entityManager", "=", "this", ".", "emHolder", ".", "get", "(", ")", ";", "if", "(", "entityManager", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"\"", ")", ";", "}", "else", "{", "entityManager", ".", "getTransaction", "(", ")", ".", "rollback", "(", ")", ";", "entityManager", ".", "close", "(", ")", ";", "emHolder", ".", "set", "(", "null", ")", ";", "}", "}", "}", "</s>" ]
9,176
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "org", ".", "apache", ".", "solr", ".", "analysis", ".", "LowerCaseFilterFactory", ";", "import", "org", ".", "apache", ".", "solr", ".", "analysis", ".", "NGramFilterFactory", ";", "import", "org", ".", "apache", ".", "solr", ".", "analysis", ".", "StandardTokenizerFactory", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Factory", ";", "import", "org", ".", "hibernate", ".", "search", ".", "cfg", ".", "SearchMapping", ";", "public", "class", "HibernateSearchMapping", "{", "@", "Factory", "SearchMapping", "getSearchMapping", "(", ")", "{", "SearchMapping", "mapping", "=", "new", "SearchMapping", "(", ")", ";", "mapping", ".", "analyzerDef", "(", "\"ngram\"", ",", "StandardTokenizerFactory", ".", "class", ")", ".", "filter", "(", "LowerCaseFilterFactory", ".", "class", ")", ".", "filter", "(", "NGramFilterFactory", ".", "class", ")", ".", "param", "(", "\"minGramSize\"", ",", "\"3\"", ")", ".", "param", "(", "\"maxGramSize\"", ",", "\"3\"", ")", ";", "return", "mapping", ";", "}", "}", "</s>" ]
9,177
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Produces", ";", "import", "javax", ".", "inject", ".", "Inject", ";", "import", "javax", ".", "persistence", ".", "EntityManager", ";", "import", "org", ".", "hibernate", ".", "search", ".", "jpa", ".", "FullTextEntityManager", ";", "import", "org", ".", "hibernate", ".", "search", ".", "jpa", ".", "Search", ";", "public", "class", "FTEMProvider", "{", "@", "Inject", "TransactionManager", "transactionManager", ";", "@", "Produces", "public", "FullTextEntityManager", "getFTEM", "(", ")", "{", "return", "Search", ".", "getFullTextEntityManager", "(", "transactionManager", ".", "getEntityManager", "(", ")", ")", ";", "}", "}", "</s>" ]
9,178
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Retention", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Target", ";", "import", "javax", ".", "interceptor", ".", "InterceptorBinding", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "*", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "RetentionPolicy", ".", "*", ";", "@", "InterceptorBinding", "@", "Target", "(", "{", "METHOD", ",", "TYPE", "}", ")", "@", "Retention", "(", "RUNTIME", ")", "public", "@", "interface", "Transactional", "{", "}", "</s>" ]
9,179
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "tools", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Disposes", ";", "import", "javax", ".", "enterprise", ".", "inject", ".", "Produces", ";", "import", "javax", ".", "inject", ".", "Singleton", ";", "import", "javax", ".", "persistence", ".", "EntityManagerFactory", ";", "import", "javax", ".", "persistence", ".", "Persistence", ";", "public", "class", "EMFProvider", "{", "@", "Produces", "@", "Singleton", "public", "EntityManagerFactory", "createEMF", "(", ")", "{", "return", "Persistence", ".", "createEntityManagerFactory", "(", "\"users\"", ")", ";", "}", "public", "void", "close", "(", "@", "Disposes", "EntityManagerFactory", "factory", ")", "{", "factory", ".", "close", "(", ")", ";", "}", "}", "</s>" ]
9,180
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "javax", ".", "persistence", ".", "Entity", ";", "import", "javax", ".", "persistence", ".", "GeneratedValue", ";", "import", "javax", ".", "persistence", ".", "Id", ";", "import", "javax", ".", "persistence", ".", "ManyToOne", ";", "@", "Entity", "public", "class", "Address", "{", "public", "Address", "(", ")", "{", "}", "public", "Address", "(", "String", "street", ",", "String", "city", ",", "String", "zipCode", ",", "User", "owner", ")", "{", "this", ".", "street", "=", "street", ";", "this", ".", "city", "=", "city", ";", "this", ".", "zipCode", "=", "zipCode", ";", "this", ".", "owner", "=", "owner", ";", "owner", ".", "getAddresses", "(", ")", ".", "add", "(", "this", ")", ";", "}", "@", "Id", "@", "GeneratedValue", "public", "Long", "getId", "(", ")", "{", "return", "id", ";", "}", "public", "void", "setId", "(", "Long", "id", ")", "{", "this", ".", "id", "=", "id", ";", "}", "private", "Long", "id", ";", "public", "String", "getStreet", "(", ")", "{", "return", "street", ";", "}", "public", "void", "setStreet", "(", "String", "street", ")", "{", "this", ".", "street", "=", "street", ";", "}", "private", "String", "street", ";", "public", "String", "getCity", "(", ")", "{", "return", "city", ";", "}", "public", "void", "setCity", "(", "String", "city", ")", "{", "this", ".", "city", "=", "city", ";", "}", "private", "String", "city", ";", "public", "String", "getZipCode", "(", ")", "{", "return", "zipCode", ";", "}", "public", "void", "setZipCode", "(", "String", "zipCode", ")", "{", "this", ".", "zipCode", "=", "zipCode", ";", "}", "private", "String", "zipCode", ";", "@", "ManyToOne", "public", "User", "getOwner", "(", ")", "{", "return", "owner", ";", "}", "public", "void", "setOwner", "(", "User", "owner", ")", "{", "this", ".", "owner", "=", "owner", ";", "}", "private", "User", "owner", ";", "}", "</s>" ]
9,181
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "public", "enum", "Gender", "{", "MALE", ",", "FEMALE", ",", "NOT_SURE", "}", "</s>" ]
9,182
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "javax", ".", "persistence", ".", "Embeddable", ";", "@", "Embeddable", "public", "class", "Login", "{", "public", "Login", "(", ")", "{", "}", "public", "Login", "(", "String", "username", ",", "String", "password", ")", "{", "this", ".", "username", "=", "username", ";", "this", ".", "password", "=", "password", ";", "}", "public", "String", "getUsername", "(", ")", "{", "return", "username", ";", "}", "public", "void", "setUsername", "(", "String", "username", ")", "{", "this", ".", "username", "=", "username", ";", "}", "private", "String", "username", ";", "public", "String", "getPassword", "(", ")", "{", "return", "password", ";", "}", "public", "void", "setPassword", "(", "String", "password", ")", "{", "this", ".", "password", "=", "password", ";", "}", "private", "String", "password", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"Login\"", ")", ";", "sb", ".", "append", "(", "\"{username='\"", ")", ".", "append", "(", "username", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "password='\"", ")", ".", "append", "(", "password", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "'}'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
9,183
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "javax", ".", "persistence", ".", "CascadeType", ";", "import", "javax", ".", "persistence", ".", "Column", ";", "import", "javax", ".", "persistence", ".", "Entity", ";", "import", "javax", ".", "persistence", ".", "GeneratedValue", ";", "import", "javax", ".", "persistence", ".", "Id", ";", "import", "javax", ".", "persistence", ".", "ManyToOne", ";", "import", "javax", ".", "persistence", ".", "Temporal", ";", "import", "javax", ".", "persistence", ".", "TemporalType", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Analyzer", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "DateBridge", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Field", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Fields", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Indexed", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "IndexedEmbedded", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "NumericField", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Resolution", ";", "@", "Entity", "@", "Indexed", "public", "class", "Book", "{", "@", "Id", "@", "GeneratedValue", "public", "Long", "getId", "(", ")", "{", "return", "id", ";", "}", "public", "void", "setId", "(", "Long", "id", ")", "{", "this", ".", "id", "=", "id", ";", "}", "private", "Long", "id", ";", "@", "Fields", "(", "{", "@", "Field", ",", "@", "Field", "(", "name", "=", "\"title_ngram\"", ",", "analyzer", "=", "@", "Analyzer", "(", "definition", "=", "\"ngram\"", ")", ")", "}", ")", "public", "String", "getTitle", "(", ")", "{", "return", "title", ";", "}", "public", "void", "setTitle", "(", "String", "title", ")", "{", "this", ".", "title", "=", "title", ";", "}", "private", "String", "title", ";", "@", "Fields", "(", "{", "@", "Field", ",", "@", "Field", "(", "name", "=", "\"\"", ",", "analyzer", "=", "@", "Analyzer", "(", "definition", "=", "\"ngram\"", ")", ")", "}", ")", "@", "Column", "(", "length", "=", "10000", ")", "public", "String", "getDescription", "(", ")", "{", "return", "description", ";", "}", "public", "void", "setDescription", "(", "String", "description", ")", "{", "this", ".", "description", "=", "description", ";", "}", "private", "String", "description", ";", "@", "Temporal", "(", "TemporalType", ".", "DATE", ")", "@", "Field", "@", "DateBridge", "(", "resolution", "=", "Resolution", ".", "DAY", ")", "public", "Date", "getPublicationDate", "(", ")", "{", "return", "publicationDate", ";", "}", "public", "void", "setPublicationDate", "(", "Date", "publicationDate", ")", "{", "this", ".", "publicationDate", "=", "publicationDate", ";", "}", "private", "Date", "publicationDate", ";", "@", "ManyToOne", "(", "cascade", "=", "CascadeType", ".", "PERSIST", ")", "@", "IndexedEmbedded", "public", "User", "getAuthor", "(", ")", "{", "return", "author", ";", "}", "public", "void", "setAuthor", "(", "User", "author", ")", "{", "this", ".", "author", "=", "author", ";", "}", "private", "User", "author", ";", "@", "Field", "@", "NumericField", "public", "int", "getNumberOfPages", "(", ")", "{", "return", "numberOfPages", ";", "}", "public", "void", "setNumberOfPages", "(", "int", "numberOfPages", ")", "{", "this", ".", "numberOfPages", "=", "numberOfPages", ";", "}", "private", "int", "numberOfPages", ";", "@", "Field", "@", "NumericField", "public", "int", "getStarred", "(", ")", "{", "return", "starred", ";", "}", "public", "void", "setStarred", "(", "int", "starred", ")", "{", "this", ".", "starred", "=", "starred", ";", "}", "private", "int", "starred", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"Book\"", ")", ";", "sb", ".", "append", "(", "\"{id=\"", ")", ".", "append", "(", "id", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "\",", "title='\"", ")", ".", "append", "(", "title", ")", ".", "append", "(", "'\\''", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "\"\"", ")", ".", "append", "(", "description", ")", ".", "append", "(", "'\\''", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "\"\"", ")", ".", "append", "(", "publicationDate", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "\",", "author=\"", ")", ".", "append", "(", "author", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "\"\"", ")", ".", "append", "(", "numberOfPages", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "\",", "starred=\"", ")", ".", "append", "(", "starred", ")", ".", "append", "(", "\"n\"", ")", ";", "sb", ".", "append", "(", "'}'", ")", ".", "append", "(", "\"n\"", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
9,184
[ "<s>", "package", "org", ".", "jboss", ".", "hibernateUniversity", ".", "criteria", ".", "domain", ";", "import", "java", ".", "util", ".", "Date", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "javax", ".", "persistence", ".", "CascadeType", ";", "import", "javax", ".", "persistence", ".", "Entity", ";", "import", "javax", ".", "persistence", ".", "EnumType", ";", "import", "javax", ".", "persistence", ".", "Enumerated", ";", "import", "javax", ".", "persistence", ".", "GeneratedValue", ";", "import", "javax", ".", "persistence", ".", "Id", ";", "import", "javax", ".", "persistence", ".", "OneToMany", ";", "import", "javax", ".", "persistence", ".", "Temporal", ";", "import", "javax", ".", "persistence", ".", "TemporalType", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Field", ";", "import", "org", ".", "hibernate", ".", "search", ".", "annotations", ".", "Indexed", ";", "@", "Entity", "@", "Indexed", "public", "class", "User", "{", "public", "User", "(", ")", "{", "}", "public", "User", "(", "String", "firstName", ",", "String", "lastName", ",", "Date", "birthDate", ",", "Gender", "gender", ",", "int", "credits", ",", "String", "username", ",", "String", "password", ")", "{", "this", ".", "firstName", "=", "firstName", ";", "this", ".", "lastName", "=", "lastName", ";", "this", ".", "birthDate", "=", "birthDate", ";", "this", ".", "gender", "=", "gender", ";", "this", ".", "credits", "=", "credits", ";", "this", ".", "login", "=", "new", "Login", "(", "username", ",", "password", ")", ";", "}", "@", "Id", "@", "GeneratedValue", "public", "Long", "getId", "(", ")", "{", "return", "id", ";", "}", "public", "void", "setId", "(", "Long", "id", ")", "{", "this", ".", "id", "=", "id", ";", "}", "private", "Long", "id", ";", "@", "Field", "public", "String", "getFirstName", "(", ")", "{", "return", "firstName", ";", "}", "public", "void", "setFirstName", "(", "String", "firstName", ")", "{", "this", ".", "firstName", "=", "firstName", ";", "}", "private", "String", "firstName", ";", "@", "Field", "public", "String", "getLastName", "(", ")", "{", "return", "lastName", ";", "}", "public", "void", "setLastName", "(", "String", "lastName", ")", "{", "this", ".", "lastName", "=", "lastName", ";", "}", "private", "String", "lastName", ";", "@", "OneToMany", "(", "cascade", "=", "CascadeType", ".", "PERSIST", ",", "mappedBy", "=", "\"owner\"", ")", "public", "Set", "<", "Address", ">", "getAddresses", "(", ")", "{", "return", "addresses", ";", "}", "public", "void", "setAddresses", "(", "Set", "<", "Address", ">", "addresses", ")", "{", "this", ".", "addresses", "=", "addresses", ";", "}", "private", "Set", "<", "Address", ">", "addresses", "=", "new", "HashSet", "<", "Address", ">", "(", ")", ";", "@", "Temporal", "(", "TemporalType", ".", "DATE", ")", "public", "Date", "getBirthDate", "(", ")", "{", "return", "birthDate", ";", "}", "public", "void", "setBirthDate", "(", "Date", "birthDate", ")", "{", "this", ".", "birthDate", "=", "birthDate", ";", "}", "private", "Date", "birthDate", ";", "@", "Enumerated", "(", "EnumType", ".", "STRING", ")", "public", "Gender", "getGender", "(", ")", "{", "return", "gender", ";", "}", "public", "void", "setGender", "(", "Gender", "gender", ")", "{", "this", ".", "gender", "=", "gender", ";", "}", "private", "Gender", "gender", ";", "public", "int", "getCredits", "(", ")", "{", "return", "credits", ";", "}", "public", "void", "setCredits", "(", "int", "credits", ")", "{", "this", ".", "credits", "=", "credits", ";", "}", "private", "int", "credits", ";", "public", "Login", "getLogin", "(", ")", "{", "return", "login", ";", "}", "public", "void", "setLogin", "(", "Login", "login", ")", "{", "this", ".", "login", "=", "login", ";", "}", "private", "Login", "login", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "\"User\"", ")", ";", "sb", ".", "append", "(", "\"{id=\"", ")", ".", "append", "(", "id", ")", ";", "sb", ".", "append", "(", "\"\"", ")", ".", "append", "(", "firstName", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "lastName='\"", ")", ".", "append", "(", "lastName", ")", ".", "append", "(", "'\\''", ")", ";", "sb", ".", "append", "(", "\",", "addresses=\"", ")", ".", "append", "(", "addresses", ")", ";", "sb", ".", "append", "(", "\",", "birthDate=\"", ")", ".", "append", "(", "birthDate", ")", ";", "sb", ".", "append", "(", "\",", "gender=\"", ")", ".", "append", "(", "gender", ")", ";", "sb", ".", "append", "(", "\",", "credits=\"", ")", ".", "append", "(", "credits", ")", ";", "sb", ".", "append", "(", "\",", "login=\"", ")", ".", "append", "(", "login", ")", ";", "sb", ".", "append", "(", "'}'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
9,185
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ";", "import", "java", ".", "math", ".", "BigDecimal", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "javax", ".", "validation", ".", "ConstraintViolation", ";", "import", "javax", ".", "validation", ".", "Validation", ";", "import", "javax", ".", "validation", ".", "Validator", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "Address", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "BlackListStatus", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "Country", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "CreditCard", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "Customer", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "Item", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "Order", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "StraightToOrderValidation", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "NoDelay", ";", "public", "class", "App", "{", "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "final", "App", "app", "=", "new", "App", "(", ")", ";", "app", ".", "testGroups", "(", ")", ";", "}", "private", "void", "testGroups", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", ")", ";", "Order", "order", "=", "buildValidOrder", "(", ")", ";", "Validator", "v", "=", "Validation", ".", "buildDefaultValidatorFactory", "(", ")", ".", "getValidator", "(", ")", ";", "Set", "<", "ConstraintViolation", "<", "Order", ">", ">", "violations", "=", "v", ".", "validate", "(", "order", ")", ";", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "violations", "=", "v", ".", "validate", "(", "order", ",", "NoDelay", ".", "class", ")", ";", "if", "(", "violations", ".", "size", "(", ")", "==", "0", ")", "{", "}", "else", "{", "}", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "order", ".", "getCustomer", "(", ")", ".", "setStatus", "(", "BlackListStatus", ".", "GREY", ")", ";", "Country", "country", "=", "new", "Country", "(", ")", ";", "country", ".", "setName", "(", "\"LalaLand\"", ")", ";", "country", ".", "setStatus", "(", "BlackListStatus", ".", "BLACK", ")", ";", "order", ".", "getShippingAddress", "(", ")", ".", "setCountry", "(", "country", ")", ";", "violations", "=", "v", ".", "validate", "(", "order", ",", "NoDelay", ".", "class", ")", ";", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "}", "private", "void", "testGroupsInheritance", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", ")", ";", "Customer", "customer", "=", "buildValidCustomer", "(", ")", ";", "Validator", "v", "=", "Validation", ".", "buildDefaultValidatorFactory", "(", ")", ".", "getValidator", "(", ")", ";", "Set", "<", "ConstraintViolation", "<", "Customer", ">", ">", "violations", "=", "v", ".", "validate", "(", "customer", ")", ";", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "violations", "=", "v", ".", "validate", "(", "customer", ",", "StraightToOrderValidation", ".", "class", ")", ";", "if", "(", "violations", ".", "size", "(", ")", "==", "0", ")", "{", "}", "else", "{", "}", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "customer", ".", "setDefaultAddress", "(", "null", ")", ";", "customer", ".", "getDefaultCreditCard", "(", ")", ".", "setNumber", "(", "\"\"", ")", ";", "violations", "=", "v", ".", "validate", "(", "customer", ",", "StraightToOrderValidation", ".", "class", ")", ";", "if", "(", "violations", ".", "size", "(", ")", "==", "0", ")", "{", "}", "else", "{", "}", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "}", "private", "void", "testComplexConstraint", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", ")", ";", "Validator", "v", "=", "Validation", ".", "buildDefaultValidatorFactory", "(", ")", ".", "getValidator", "(", ")", ";", "Address", "address", "=", "buildvalidAddress", "(", ")", ";", "address", ".", "setZipCode", "(", "\"123456\"", ")", ";", "Set", "<", "ConstraintViolation", "<", "Address", ">", ">", "violations", "=", "v", ".", "validate", "(", "address", ")", ";", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "}", "private", "void", "testComposition", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"\"", ")", ";", "Order", "order", "=", "buildValidOrder", "(", ")", ";", "Validator", "v", "=", "Validation", ".", "buildDefaultValidatorFactory", "(", ")", ".", "getValidator", "(", ")", ";", "order", ".", "setOrderNumber", "(", "\"123456789\"", ")", ";", "Set", "<", "ConstraintViolation", "<", "Order", ">", ">", "violations", "=", "v", ".", "validate", "(", "order", ")", ";", "displayViolations", "(", "\"\"", ",", "violations", ")", ";", "}", "private", "<", "T", ">", "void", "displayViolations", "(", "String", "message", ",", "Set", "<", "ConstraintViolation", "<", "T", ">", ">", "violations", ")", "{", "StringBuilder", "errorReport", "=", "new", "StringBuilder", "(", "\"n\"", ")", ";", "errorReport", ".", "append", "(", "message", ")", ".", "append", "(", "\"n\"", ")", ";", "if", "(", "violations", ".", "size", "(", ")", "==", "0", ")", "{", "errorReport", ".", "append", "(", "\"\"", ")", ";", "}", "else", "{", "errorReport", ".", "append", "(", "\"Found", "\"", ")", ".", "append", "(", "violations", ".", "size", "(", ")", ")", ".", "append", "(", "\"", "error\"", ")", ";", "if", "(", "violations", ".", "size", "(", ")", ">", "1", ")", "{", "errorReport", ".", "append", "(", "\"s\"", ")", ";", "}", "for", "(", "ConstraintViolation", "violation", ":", "violations", ")", "{", "errorReport", ".", "append", "(", "\"nttin", "\"", ")", ".", "append", "(", "violation", ".", "getRootBeanClass", "(", ")", ".", "getName", "(", ")", ")", ".", "append", "(", "\".\"", ")", ".", "append", "(", "violation", ".", "getPropertyPath", "(", ")", ")", ";", "errorReport", ".", "append", "(", "\"\"", ")", ".", "append", "(", "violation", ".", "getMessage", "(", ")", ")", ".", "append", "(", "\"'\"", ")", ";", "}", "}", "System", ".", "out", ".", "println", "(", "errorReport", ".", "toString", "(", ")", ")", ";", "}", "private", "Order", "buildValidOrder", "(", ")", "{", "Address", "address", "=", "buildvalidAddress", "(", ")", ";", "CreditCard", "creditCard", "=", "buildValidCreditCard", "(", ")", ";", "Item", "item", "=", "new", "Item", "(", ")", ";", "item", ".", "setDescription", "(", "\"\"", ")", ";", "item", ".", "setPrice", "(", "new", "BigDecimal", "(", "\"1499.9\"", ")", ")", ";", "item", ".", "setStock", "(", "3", ")", ";", "Customer", "customer", "=", "new", "Customer", "(", ")", ";", "customer", ".", "setFirstname", "(", "\"Emmanuel\"", ")", ";", "customer", ".", "setLastname", "(", "\"Bernard\"", ")", ";", "customer", ".", "setStatus", "(", "BlackListStatus", ".", "OK", ")", ";", "Order", "order", "=", "new", "Order", "(", ")", ";", "order", ".", "setCreditCard", "(", "creditCard", ")", ";", "order", ".", "setCustomer", "(", "customer", ")", ";", "order", ".", "setShippingAddress", "(", "address", ")", ";", "order", ".", "getItems", "(", ")", ".", "add", "(", "item", ")", ";", "order", ".", "setOrderNumber", "(", "\"1234567897\"", ")", ";", "return", "order", ";", "}", "private", "Address", "buildvalidAddress", "(", ")", "{", "Country", "country", "=", "new", "Country", "(", ")", ";", "country", ".", "setName", "(", "\"USA\"", ")", ";", "country", ".", "setStatus", "(", "BlackListStatus", ".", "OK", ")", ";", "Address", "address", "=", "new", "Address", "(", ")", ";", "address", ".", "setStreet1", "(", "\"\"", ")", ";", "address", ".", "setCity", "(", "\"Atlanta,", "GA\"", ")", ";", "address", ".", "setCountry", "(", "country", ")", ";", "address", ".", "setZipCode", "(", "\"30300\"", ")", ";", "return", "address", ";", "}", "private", "Customer", "buildValidCustomer", "(", ")", "{", "Address", "address", "=", "buildvalidAddress", "(", ")", ";", "CreditCard", "creditCard", "=", "buildValidCreditCard", "(", ")", ";", "Customer", "customer", "=", "new", "Customer", "(", ")", ";", "customer", ".", "setDefaultAddress", "(", "address", ")", ";", "customer", ".", "setDefaultCreditCard", "(", "creditCard", ")", ";", "customer", ".", "setFirstname", "(", "\"Emmanuel\"", ")", ";", "customer", ".", "setLastname", "(", "\"Bernard\"", ")", ";", "customer", ".", "setStatus", "(", "BlackListStatus", ".", "OK", ")", ";", "return", "customer", ";", "}", "private", "CreditCard", "buildValidCreditCard", "(", ")", "{", "CreditCard", "creditCard", "=", "new", "CreditCard", "(", ")", ";", "creditCard", ".", "setNumber", "(", "\"\"", ")", ";", "creditCard", ".", "setOwner", "(", "\"\"", ")", ";", "return", "creditCard", ";", "}", "}", "</s>" ]
9,186
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "public", "enum", "BlackListStatus", "{", "OK", ",", "GREY", ",", "BLACK", "}", "</s>" ]
9,187
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ";", "public", "interface", "NoDelay", "{", "}", "</s>" ]
9,188
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ";", "import", "java", ".", "lang", ".", "annotation", ".", "ElementType", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Retention", ";", "import", "java", ".", "lang", ".", "annotation", ".", "RetentionPolicy", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Target", ";", "import", "javax", ".", "validation", ".", "Constraint", ";", "import", "javax", ".", "validation", ".", "ConstraintValidator", ";", "import", "javax", ".", "validation", ".", "ConstraintValidatorContext", ";", "import", "javax", ".", "validation", ".", "Payload", ";", "import", "org", ".", "hibernate", ".", "validator", ".", "constraints", ".", "impl", ".", "LuhnValidator", ";", "@", "Retention", "(", "RetentionPolicy", ".", "RUNTIME", ")", "@", "Target", "(", "{", "ElementType", ".", "METHOD", ",", "ElementType", ".", "FIELD", ",", "ElementType", ".", "ANNOTATION_TYPE", ",", "ElementType", ".", "PARAMETER", "}", ")", "@", "Constraint", "(", "validatedBy", "=", "Luhn", ".", "Validator", ".", "class", ")", "public", "@", "interface", "Luhn", "{", "String", "message", "(", ")", "default", "\"\"", ";", "Class", "<", "?", ">", "[", "]", "groups", "(", ")", "default", "{", "}", ";", "Class", "<", "?", "extends", "Payload", ">", "[", "]", "payload", "(", ")", "default", "{", "}", ";", "public", "class", "Validator", "implements", "ConstraintValidator", "<", "Luhn", ",", "String", ">", "{", "private", "LuhnValidator", "validator", "=", "new", "LuhnValidator", "(", "2", ")", ";", "public", "void", "initialize", "(", "Luhn", "constraintAnnotation", ")", "{", "}", "public", "boolean", "isValid", "(", "String", "value", ",", "ConstraintValidatorContext", "context", ")", "{", "if", "(", "value", "==", "null", ")", "{", "return", "true", ";", "}", "return", "validator", ".", "passesLuhnTest", "(", "value", ")", ";", "}", "}", "}", "</s>" ]
9,189
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ";", "import", "java", ".", "lang", ".", "annotation", ".", "ElementType", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Retention", ";", "import", "java", ".", "lang", ".", "annotation", ".", "RetentionPolicy", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Target", ";", "import", "javax", ".", "validation", ".", "Constraint", ";", "import", "javax", ".", "validation", ".", "OverridesAttribute", ";", "import", "javax", ".", "validation", ".", "Payload", ";", "import", "javax", ".", "validation", ".", "ReportAsSingleViolation", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "Size", ";", "@", "Retention", "(", "RetentionPolicy", ".", "RUNTIME", ")", "@", "Target", "(", "{", "ElementType", ".", "METHOD", ",", "ElementType", ".", "FIELD", ",", "ElementType", ".", "ANNOTATION_TYPE", ",", "ElementType", ".", "PARAMETER", "}", ")", "@", "Constraint", "(", "validatedBy", "=", "{", "}", ")", "@", "Size", "(", "min", "=", "10", ",", "max", "=", "10", ",", "message", "=", "\"\"", ")", "@", "Luhn", "(", "message", "=", "\"\"", ")", "@", "ReportAsSingleViolation", "public", "@", "interface", "OrderNumber", "{", "String", "message", "(", ")", "default", "\"\"", ";", "Class", "<", "?", ">", "[", "]", "groups", "(", ")", "default", "{", "}", ";", "Class", "<", "?", "extends", "Payload", ">", "[", "]", "payload", "(", ")", "default", "{", "}", ";", "@", "OverridesAttribute", ".", "List", "(", "{", "@", "OverridesAttribute", "(", "constraint", "=", "Size", ".", "class", ",", "name", "=", "\"min\"", ")", ",", "@", "OverridesAttribute", "(", "constraint", "=", "Size", ".", "class", ",", "name", "=", "\"max\"", ")", "}", ")", "int", "size", "(", ")", ";", "}", "</s>" ]
9,190
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ";", "import", "java", ".", "lang", ".", "annotation", ".", "ElementType", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Retention", ";", "import", "java", ".", "lang", ".", "annotation", ".", "RetentionPolicy", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Target", ";", "import", "javax", ".", "validation", ".", "Constraint", ";", "import", "javax", ".", "validation", ".", "Payload", ";", "import", "javax", ".", "validation", ".", "ReportAsSingleViolation", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "Size", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "impl", ".", "ZipCodeValidator", ";", "@", "Retention", "(", "RetentionPolicy", ".", "RUNTIME", ")", "@", "Target", "(", "{", "ElementType", ".", "METHOD", ",", "ElementType", ".", "TYPE", ",", "ElementType", ".", "ANNOTATION_TYPE", ",", "ElementType", ".", "PARAMETER", "}", ")", "@", "Constraint", "(", "validatedBy", "=", "{", "ZipCodeValidator", ".", "class", "}", ")", "public", "@", "interface", "ZipCode", "{", "String", "message", "(", ")", "default", "\"\"", ";", "Class", "<", "?", ">", "[", "]", "groups", "(", ")", "default", "{", "}", ";", "Class", "<", "?", "extends", "Payload", ">", "[", "]", "payload", "(", ")", "default", "{", "}", ";", "}", "</s>" ]
9,191
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Documented", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Retention", ";", "import", "java", ".", "lang", ".", "annotation", ".", "Target", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "javax", ".", "validation", ".", "Constraint", ";", "import", "javax", ".", "validation", ".", "ConstraintValidator", ";", "import", "javax", ".", "validation", ".", "ConstraintValidatorContext", ";", "import", "javax", ".", "validation", ".", "Payload", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "BlackListStatus", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "ANNOTATION_TYPE", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "CONSTRUCTOR", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "FIELD", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "METHOD", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "ElementType", ".", "PARAMETER", ";", "import", "static", "java", ".", "lang", ".", "annotation", ".", "RetentionPolicy", ".", "RUNTIME", ";", "@", "Target", "(", "{", "METHOD", ",", "FIELD", ",", "ANNOTATION_TYPE", ",", "CONSTRUCTOR", ",", "PARAMETER", "}", ")", "@", "Retention", "(", "RUNTIME", ")", "@", "Documented", "@", "Constraint", "(", "validatedBy", "=", "CheckBlackListStatus", ".", "Validator", ".", "class", ")", "public", "@", "interface", "CheckBlackListStatus", "{", "String", "message", "(", ")", "default", "\"\"", ";", "Class", "<", "?", ">", "[", "]", "groups", "(", ")", "default", "{", "}", ";", "Class", "<", "?", "extends", "Payload", ">", "[", "]", "payload", "(", ")", "default", "{", "}", ";", "BlackListStatus", "[", "]", "accepted", "(", ")", ";", "public", "class", "Validator", "implements", "ConstraintValidator", "<", "CheckBlackListStatus", ",", "BlackListStatus", ">", "{", "private", "List", "<", "BlackListStatus", ">", "accepted", ";", "public", "void", "initialize", "(", "CheckBlackListStatus", "constraintAnnotation", ")", "{", "final", "BlackListStatus", "[", "]", "statuses", "=", "constraintAnnotation", ".", "accepted", "(", ")", ";", "accepted", "=", "new", "ArrayList", "<", "BlackListStatus", ">", "(", "statuses", ".", "length", ")", ";", "for", "(", "BlackListStatus", "current", ":", "statuses", ")", "{", "accepted", ".", "add", "(", "current", ")", ";", "}", "}", "public", "boolean", "isValid", "(", "BlackListStatus", "value", ",", "ConstraintValidatorContext", "context", ")", "{", "return", "accepted", ".", "contains", "(", "value", ")", ";", "}", "}", "}", "</s>" ]
9,192
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "impl", ";", "import", "javax", ".", "validation", ".", "ConstraintValidator", ";", "import", "javax", ".", "validation", ".", "ConstraintValidatorContext", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "Address", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "ZipCode", ";", "public", "class", "ZipCodeValidator", "implements", "ConstraintValidator", "<", "ZipCode", ",", "Address", ">", "{", "public", "void", "initialize", "(", "ZipCode", "constraintAnnotation", ")", "{", "}", "public", "boolean", "isValid", "(", "Address", "value", ",", "ConstraintValidatorContext", "context", ")", "{", "if", "(", "value", "==", "null", ")", "return", "true", ";", "context", ".", "disableDefaultConstraintViolation", "(", ")", ";", "String", "countryName", "=", "value", ".", "getCountry", "(", ")", "==", "null", "?", "null", ":", "value", ".", "getCountry", "(", ")", ".", "getName", "(", ")", ";", "boolean", "result", "=", "true", ";", "if", "(", "countryName", "==", "null", ")", "{", "context", ".", "buildConstraintViolationWithTemplate", "(", "\"\"", ")", ".", "addNode", "(", "\"country\"", ")", ".", "addConstraintViolation", "(", ")", ";", "result", "=", "false", ";", "}", "String", "zipCode", "=", "value", ".", "getZipCode", "(", ")", ";", "if", "(", "zipCode", "==", "null", ")", "{", "context", ".", "buildConstraintViolationWithTemplate", "(", "\"\"", ")", ".", "addNode", "(", "\"zipCode\"", ")", ".", "addConstraintViolation", "(", ")", ";", "result", "=", "false", ";", "}", "if", "(", "!", "result", ")", "return", "false", ";", "if", "(", "\"France\"", ".", "equals", "(", "countryName", ")", ")", "{", "return", "validateFrenchZipCode", "(", "value", ".", "getZipCode", "(", ")", ",", "context", ")", ";", "}", "else", "if", "(", "\"USA\"", ".", "equals", "(", "countryName", ")", ")", "{", "return", "validateUSAZipCode", "(", "zipCode", ",", "context", ")", ";", "}", "return", "true", ";", "}", "private", "boolean", "validateFrenchZipCode", "(", "String", "zipCode", ",", "ConstraintValidatorContext", "context", ")", "{", "if", "(", "zipCode", ".", "length", "(", ")", "!=", "5", ")", "{", "context", ".", "buildConstraintViolationWithTemplate", "(", "\"\"", ")", ".", "addNode", "(", "\"zipCode\"", ")", ".", "addConstraintViolation", "(", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}", "private", "boolean", "validateUSAZipCode", "(", "String", "zipCode", ",", "ConstraintValidatorContext", "context", ")", "{", "if", "(", "zipCode", ".", "length", "(", ")", "!=", "5", ")", "{", "context", ".", "buildConstraintViolationWithTemplate", "(", "\"\"", ")", ".", "addNode", "(", "\"zipCode\"", ")", ".", "addConstraintViolation", "(", ")", ";", "return", "false", ";", "}", "if", "(", "!", "isInUSPSDatabase", "(", "zipCode", ")", ")", "{", "context", ".", "buildConstraintViolationWithTemplate", "(", "\"\"", ")", ".", "addNode", "(", "\"zipCode\"", ")", ".", "addConstraintViolation", "(", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}", "private", "boolean", "isInUSPSDatabase", "(", "String", "zipCode", ")", "{", "return", "true", ";", "}", "}", "</s>" ]
9,193
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "public", "interface", "BillableAutomatically", "{", "}", "</s>" ]
9,194
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "import", "java", ".", "math", ".", "BigDecimal", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "DecimalMax", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "DecimalMin", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "Min", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "NotNull", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "Size", ";", "import", "org", ".", "hibernate", ".", "validator", ".", "constraints", ".", "NotEmpty", ";", "public", "class", "Item", "{", "@", "NotEmpty", "@", "Size", "(", "max", "=", "250", ")", "public", "String", "getDescription", "(", ")", "{", "return", "description", ";", "}", "public", "void", "setDescription", "(", "String", "description", ")", "{", "this", ".", "description", "=", "description", ";", "}", "private", "String", "description", ";", "@", "DecimalMin", "(", "value", "=", "\"1.00\"", ")", "public", "BigDecimal", "getPrice", "(", ")", "{", "return", "price", ";", "}", "public", "void", "setPrice", "(", "BigDecimal", "price", ")", "{", "this", ".", "price", "=", "price", ";", "}", "private", "BigDecimal", "price", ";", "@", "NotNull", "@", "Min", "(", "value", "=", "0", ")", "public", "Integer", "getStock", "(", ")", "{", "return", "stock", ";", "}", "public", "void", "setStock", "(", "Integer", "stock", ")", "{", "this", ".", "stock", "=", "stock", ";", "}", "private", "Integer", "stock", ";", "}", "</s>" ]
9,195
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "import", "javax", ".", "validation", ".", "groups", ".", "Default", ";", "public", "interface", "StraightToOrderValidation", "extends", "ShippableAutomatically", ",", "BillableAutomatically", ",", "Default", "{", "}", "</s>" ]
9,196
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "import", "javax", ".", "validation", ".", "Valid", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "ZipCode", ";", "@", "ZipCode", "public", "class", "Address", "{", "public", "String", "getStreet1", "(", ")", "{", "return", "street1", ";", "}", "public", "void", "setStreet1", "(", "String", "street1", ")", "{", "this", ".", "street1", "=", "street1", ";", "}", "private", "String", "street1", ";", "public", "String", "getCity", "(", ")", "{", "return", "city", ";", "}", "public", "void", "setCity", "(", "String", "city", ")", "{", "this", ".", "city", "=", "city", ";", "}", "private", "String", "city", ";", "public", "String", "getZipCode", "(", ")", "{", "return", "zipCode", ";", "}", "public", "void", "setZipCode", "(", "String", "zipCode", ")", "{", "this", ".", "zipCode", "=", "zipCode", ";", "}", "private", "String", "zipCode", ";", "@", "Valid", "public", "Country", "getCountry", "(", ")", "{", "return", "country", ";", "}", "public", "void", "setCountry", "(", "Country", "country", ")", "{", "this", ".", "country", "=", "country", ";", "}", "private", "Country", "country", ";", "}", "</s>" ]
9,197
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "import", "javax", ".", "validation", ".", "Valid", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "NotNull", ";", "import", "javax", ".", "validation", ".", "constraints", ".", "Size", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "CheckBlackListStatus", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "NoDelay", ";", "import", "org", ".", "hibernate", ".", "validator", ".", "constraints", ".", "NotEmpty", ";", "public", "class", "Customer", "{", "@", "NotEmpty", "@", "Size", "(", "max", "=", "50", ")", "public", "String", "getFirstname", "(", ")", "{", "return", "firstname", ";", "}", "public", "void", "setFirstname", "(", "String", "firstname", ")", "{", "this", ".", "firstname", "=", "firstname", ";", "}", "private", "String", "firstname", ";", "@", "NotEmpty", "@", "Size", "(", "max", "=", "50", ")", "public", "String", "getLastname", "(", ")", "{", "return", "lastname", ";", "}", "public", "void", "setLastname", "(", "String", "lastname", ")", "{", "this", ".", "lastname", "=", "lastname", ";", "}", "private", "String", "lastname", ";", "@", "Valid", "@", "NotNull", "(", "groups", "=", "ShippableAutomatically", ".", "class", ",", "message", "=", "\"\"", ")", "public", "Address", "getDefaultAddress", "(", ")", "{", "return", "defaultAddress", ";", "}", "public", "void", "setDefaultAddress", "(", "Address", "defaultAddress", ")", "{", "this", ".", "defaultAddress", "=", "defaultAddress", ";", "}", "private", "Address", "defaultAddress", ";", "@", "Valid", "@", "NotNull", "(", "groups", "=", "BillableAutomatically", ".", "class", ",", "message", "=", "\"\"", ")", "public", "CreditCard", "getDefaultCreditCard", "(", ")", "{", "return", "defaultCreditCard", ";", "}", "public", "void", "setDefaultCreditCard", "(", "CreditCard", "defaultCreditCard", ")", "{", "this", ".", "defaultCreditCard", "=", "defaultCreditCard", ";", "}", "private", "CreditCard", "defaultCreditCard", ";", "@", "CheckBlackListStatus", "(", "accepted", "=", "BlackListStatus", ".", "OK", ",", "message", "=", "\"\"", ",", "groups", "=", "NoDelay", ".", "class", ")", "public", "BlackListStatus", "getStatus", "(", ")", "{", "return", "status", ";", "}", "public", "void", "setStatus", "(", "BlackListStatus", "status", ")", "{", "this", ".", "status", "=", "status", ";", "}", "private", "BlackListStatus", "status", ";", "}", "</s>" ]
9,198
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "public", "interface", "ShippableAutomatically", "{", "}", "</s>" ]
9,199
[ "<s>", "package", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "CheckBlackListStatus", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "NoDelay", ";", "import", "com", ".", "jboss", ".", "sample", ".", "bv", ".", "domain", ".", "constraints", ".", "ZipCode", ";", "import", "org", ".", "hibernate", ".", "validator", ".", "constraints", ".", "NotEmpty", ";", "public", "class", "Country", "{", "@", "NotEmpty", "public", "String", "getName", "(", ")", "{", "return", "name", ";", "}", "public", "void", "setName", "(", "String", "name", ")", "{", "this", ".", "name", "=", "name", ";", "}", "private", "String", "name", ";", "@", "CheckBlackListStatus", "(", "accepted", "=", "BlackListStatus", ".", "OK", ",", "groups", "=", "NoDelay", ".", "class", ",", "message", "=", "\"\"", ")", "public", "BlackListStatus", "getStatus", "(", ")", "{", "return", "status", ";", "}", "public", "void", "setStatus", "(", "BlackListStatus", "status", ")", "{", "this", ".", "status", "=", "status", ";", "}", "private", "BlackListStatus", "status", ";", "}", "</s>" ]