id
stringlengths
36
36
text
stringlengths
1
1.25M
12cf6a93-99cc-4f0f-bdfb-47bfab21e647
private int[] getIndexes(String name) { int[] indexes = (int[]) indexMap.get(name); if (indexes == null) { throw new IllegalArgumentException("Parameter not found: " + name); } return indexes; }
66b6623e-6c4f-47e5-a5cd-ffc8a1c8e32c
public void setObject(String name, Object value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setObject(indexes[i], value); } }
0c9e4679-b842-4a3d-97cd-d71af01e2c80
public void setString(String name, String value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setString(indexes[i], value); } }
5c1ff0ee-9416-4596-965c-0105600a6d04
public void setInt(String name, int value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setInt(indexes[i], value); } }
91cc5e5f-c931-41df-bd6f-9020f90c3910
public void setLong(String name, long value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setLong(indexes[i], value); } }
3f9980d6-e5f0-4a47-8b99-9b8c5916826f
public void setFloat(String name, float value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setFloat(indexes[i], value); } }
27268f2e-4e2e-43ca-8d2c-32b573f1506f
public void setDouble(String name, double value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setDouble(indexes[i], value); } }
7582af8d-b080-4869-9708-6c1518a0da27
public void setBigDecimal(String name, BigDecimal value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setBigDecimal(indexes[i], value); } }
0165e45e-2a72-4aff-9c0a-f7410825d3c6
public void setBytes(String name, byte[] data) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setBytes(indexes[i], data); } }
e5040ebe-27ad-4995-bd56-4adb5e3d9aff
public void setTimestamp(String name, Timestamp value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setTimestamp(indexes[i], value); } }
9ed9abb7-3373-4792-b4f1-854696cfb345
public void setDate(String name, Date value) throws SQLException { int[] indexes = getIndexes(name); for (int i = 0; i < indexes.length; i++) { statement.setDate(indexes[i], new java.sql.Date(value.getTime())); } }
a45b81ee-088b-4e89-af46-b2559a34ec59
public PreparedStatement getStatement() { return statement; }
fe48595e-5102-4196-8489-5915ed89ad0c
public boolean execute() throws SQLException { return statement.execute(); }
b30a7ec6-014e-4bac-875a-c36ae96e9da5
public ResultSet executeQuery() throws SQLException { return statement.executeQuery(); }
ca488b62-bbaf-4288-8d7c-771b7f896baf
public int executeUpdate() throws SQLException { return statement.executeUpdate(); }
314c3744-09a1-4b33-9a90-eb8cfbfdb9b6
public void close() throws SQLException { statement.close(); }
ca8bc9ef-ea65-4267-9acb-b9511103999e
public void addBatch() throws SQLException { statement.addBatch(); }
ead35d7c-450b-455e-8184-d5890cef48c2
public int[] executeBatch() throws SQLException { return statement.executeBatch(); }
b04b8ffb-3c3e-461c-8f72-6cf070731f9e
public TransactionImpl(Connection connection) throws SQLException { this.connection = connection; this.connection.setAutoCommit(false); }
8dd7fb1a-d685-4562-ab39-8c28631c3357
@Override public void commit() throws SQLException { this.connection.commit(); JdbcUtil.close(this.connection); }
ffc259f0-4928-4043-8c9a-d15b2e4f044e
@Override public void rollback() throws SQLException { this.connection.rollback(); JdbcUtil.close(this.connection); }
dc3306f8-5153-4cd5-b339-19f6e6d4306a
@Override public Query query(String statement) throws SQLException { return new QueryImpl(connection, statement, false); }
70dd6e29-55bb-4e80-8a8e-ea2c4e07863e
@Override public Update update(String statement) throws SQLException { return new UpdateImpl(connection, statement, false); }
421b48c6-f0fe-4d68-b270-549fa35f0e4c
public UpdateImpl(Connection connection, String statement, boolean autoClose) throws SQLException { super(connection, statement); this.autoClose = autoClose; }
8932029a-76cb-4de4-992d-dd5882be973b
@Override public void execute() throws SQLException { namedParameterStatement.execute(); if (autoClose) { close(); } }
91456f9e-f375-4c18-968d-a1e775a29e9d
public Statement(Connection connection, String statement) throws SQLException { con = connection; namedParameterStatement = new NamedParameterStatement(connection, statement); }
ac252c8d-7d7f-456c-b9ca-b8ffb1c9d118
public T setString(String name, String value) { try { namedParameterStatement.setString(name, value); return (T)this; } catch (SQLException e) { throw new DatabaseException(e); } }
fc45f94d-9957-4bf0-aa4a-9c411653942e
public T setInteger(String name, Integer value) { try { namedParameterStatement.setInt(name, value); return (T)this; } catch (SQLException e) { throw new DatabaseException(e); } }
c63ea1ef-5b3c-4289-a501-b81172ee58d3
public T setLong(String name, Long value) { try { namedParameterStatement.setLong(name, value); return (T)this; } catch (SQLException e) { throw new DatabaseException(e); } }
f6f2d4f6-0776-441a-9637-c49fdadeff14
public T setDate(String name, Date value) { try { namedParameterStatement.setDate(name, value); return (T)this; } catch (SQLException e) { throw new DatabaseException(e); } }
7b5151fb-9c3f-4f55-816b-95a90e43887a
public T setBoolean(String name, Boolean value) { try { namedParameterStatement.setObject(name, value); return (T)this; } catch (SQLException e) { throw new DatabaseException(e); } }
02a524ae-3df2-4b4b-8eca-24bc2cabe34c
public T setTimestamp(String name, Date value) { try { namedParameterStatement.setTimestamp(name, new Timestamp(value.getTime())); return (T)this; } catch (SQLException e) { throw new DatabaseException(e); } }
110d6730-b58e-4d74-a243-338a4ed2bcf9
public void close() { if (namedParameterStatement != null) { try { namedParameterStatement.close(); } catch (SQLException e) { //Ignore } } if (con != null) { try { con.close(); } catch (SQLException e) { //Ignore } } }
b415946f-c8fe-455e-a571-a2c258fa427f
public static void close(Connection con) { if (con != null) { try { con.close(); } catch (SQLException ex) { ex.printStackTrace(); } } }
30db49dd-180f-48ec-9748-4011a736df12
public static void close(PreparedStatement ps) { if (ps != null) { try { ps.close(); } catch (SQLException ex) { ex.printStackTrace(); } } }
87717b9d-102d-4709-8add-ca2c57dc49df
public static void close(ResultSet rs) { if (rs != null) { try { rs.close(); } catch (SQLException ex) { ex.printStackTrace(); } } }
02865fb5-87ac-4a2f-82a1-f3a0cac99396
public QueryImpl(Connection connection, String statement, boolean autoClose) throws SQLException { super(connection, statement); this.autoClose = autoClose; }
043f54bd-5330-4e69-bf35-cfdc638c6355
@Override public List<T> queryForList(RowMapper<T> rowMapper) throws SQLException { List<T> out = new ArrayList<T>(); ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); while (rs.next()) { out.add(rowMapper.mapRow(rs)); } return out; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
a859555f-7677-4bd2-a6e0-569618887c59
@Override public Object queryForObject(RowMapper rowMapper) throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return rowMapper.mapRow(rs); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
91d665d0-6b06-456b-87a9-83eea78982b1
@Override public String queryForString() throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return rs.getString(1); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
d60e0c70-9b82-47ab-b64a-d9a3b670ae2f
@Override public Integer queryForInteger() throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return Integer.valueOf(rs.getInt(1)); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
32784600-fd7e-4f75-8a34-70042b9d8344
@Override public Long queryForLong() throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return rs.getLong(1); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
c54ec4be-b2c3-4b62-bb18-e20399f5e2ff
@Override public Date queryForDate() throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return rs.getDate(1); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
6e9e9c8f-eafc-483a-8bdb-955ade57c1cd
@Override public Date queryForTimestamp() throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return new Date(rs.getTimestamp(1).getTime()); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
47e16811-317e-428c-9311-9993a0709635
@Override public Boolean queryForBoolean() throws SQLException { ResultSet rs = null; try { rs = namedParameterStatement.executeQuery(); if (rs.next()) { return rs.getBoolean(1); } return null; } finally { JdbcUtil.close(rs); if (autoClose) { close(); } } }
cde88224-632d-439f-8fb1-30bb3b56b1cd
@org.junit.Test public void testQuery() throws Exception { //given Database db = new Database("org.h2.Driver", "jdbc:h2:target/test", "sa", ""); //when db.update("DROP TABLE IF EXISTS test ").execute(); db.update("CREATE TABLE test(val1 int, val2 varchar(10), val3 date)").execute(); db.update("INSERT INTO test VALUES (1, 'abc', CURRENT_DATE())").execute(); db.update("INSERT INTO test VALUES (2, 'def', CURRENT_DATE())").execute(); Query qry = db.query("SELECT * FROM test"); List<Test> items = qry.queryForList(new RowMapper<Test>(){ @Override public Test mapRow(ResultSet rs) throws SQLException { return new Test(rs.getInt("val1"), rs.getString("val2"), rs.getDate("val3")); } }); //then assertEquals(2, items.size()); db.close(); }
7b39de98-e9ae-4ef4-8b13-c6ad8432d33c
@Override public Test mapRow(ResultSet rs) throws SQLException { return new Test(rs.getInt("val1"), rs.getString("val2"), rs.getDate("val3")); }
5c9e597f-3cf8-46d5-89dd-ecd4293f60a7
@org.junit.Test public void testUpdate() throws Exception { //given Database db = new Database("org.h2.Driver", "jdbc:h2:target/test", "sa", ""); //when db.update("DROP TABLE IF EXISTS test ").execute(); db.update("CREATE TABLE test (val1 int, val2 varchar(10), val3 date)").execute(); db.update("INSERT INTO test VALUES (1, 'abc', CURRENT_DATE())").execute(); db.update("UPDATE test SET val1 = 10 where val1 = 1").execute(); String val = db.query("SELECT val2 FROM test WHERE val1 = 10").queryForString(); //then assertEquals("abc", val); db.close(); }
1e6e2132-967a-4c8d-a718-2e16a60ef226
@org.junit.Test public void testStartTransaction() throws Exception { //given Database db = new Database("org.h2.Driver", "jdbc:h2:target/test", "sa", ""); //when db.update("DROP TABLE IF EXISTS test ").execute(); db.update("CREATE TABLE test (val1 int, val2 varchar(10), val3 date)").execute(); Transaction tr = db.startTransaction(); tr.update("INSERT INTO test VALUES (1, 'abc', CURRENT_DATE())").execute(); tr.commit(); String val = db.query("SELECT val2 FROM test WHERE val1 = 1").queryForString(); //then assertEquals("abc", val); db.close(); }
11866adc-9877-46f3-acff-c9abcd9e823a
Test(int val1, String val2, Date val3) { this.val1 = val1; this.val2 = val2; this.val3 = val3; }
04276666-4f03-43e7-8d87-fbd98a48778c
public int getVal1() { return val1; }
97e759c6-97a0-4ac9-a24f-9f3ff1e86798
public String getVal2() { return val2; }
c99b1841-bc1e-4164-8e0f-b39250665164
public Date getVal3() { return val3; }
c38d4b3b-0619-40c6-a385-60bec402d4e6
public int compare(Task t1, Task t2) { if(t1.get_cTime()<t2.get_cTime()) return -1; else if(t1.get_cTime()==t2.get_cTime()) return 0; else if(t1.get_cTime()>t2.get_cTime()) return 1; return -2; }
aea38cad-9e76-4fb7-97ea-b2b020c1a331
public ETCGenerator(int NUM_MACHINES, int NUM_TASKS, TaskHeterogeneity TASK_HETEROGENEITY, MachineHeterogeneity MACHINE_HETEROGENEITY) { m=NUM_MACHINES; n=NUM_TASKS; e=new int[n][m];/*e[i][j] represents the time taken to complete the ith task on the jth machine.*/ T_t=TASK_HETEROGENEITY.getNumericValue(); T_m=MACHINE_HETEROGENEITY.getNumericValue(); }
b6beca56-c1db-47e8-bdbf-20eb81fec5c8
public ETCGenerator ETCEngine(int NUM_MACHINES, int NUM_TASKS, TaskHeterogeneity TASK_HETEROGENEITY, MachineHeterogeneity MACHINE_HETEROGENEITY) { m=NUM_MACHINES; n=NUM_TASKS; e=new int[n][m];/*e[i][j] represents the time taken to complete the ith task on the jth machine.*/ T_t=TASK_HETEROGENEITY.getNumericValue(); T_m=MACHINE_HETEROGENEITY.getNumericValue(); return this; }
a335d249-54e5-4ad4-a756-302b3992217a
private void generateETC(){ Random rt=new Random(); Random rm=new Random(); int q[]=new int[n]; for(int i=0;i<n;i++){ int N_t=rt.nextInt(T_t); q[i]=N_t; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ int N_m=rm.nextInt(T_m); e[i][j]=q[i]*N_m +1; } } }
9b4eb8e4-16cb-45b5-bbf7-2eb779510f6a
public int[][] getETC(){ generateETC(); return e; }
6335c974-c5af-4250-bf96-6c7d0dd46ab8
@Override public String toString(){ String s=Arrays.deepToString(this.getETC()); return s; }
12c69ed0-8a7b-441b-a353-6e2ee6694716
public static void main(String...args){ TaskHeterogeneity TH = null; MachineHeterogeneity MH=null; int ee[][]=new ETCGenerator(3,10,TH.LOW,MH.LOW).getETC(); out.println(Arrays.deepToString(ee)); }
b745bd2d-2e24-4df2-886c-6db4cd8af56f
public SimulatorEngine(int NUM_MACHINES, int NUM_TASKS, double ARRIVAL_RATE, int metaSetSize,Heuristic HEURISTIC, TaskHeterogeneity th, MachineHeterogeneity mh){ sigma=0; makespan=0; MH=mh; TH=th; n=NUM_TASKS; S=metaSetSize; m=NUM_MACHINES; lambda=ARRIVAL_RATE; comparator=new TaskComparator(); p=new PriorityQueue[m]; eng=new SchedulingEngine(this,HEURISTIC); for(int i=0;i<p.length;i++) p[i]=new PriorityQueue<Task>(5,comparator); generateRandoms(); mat=new int[m]; }
581f4da7-a04b-44bd-9317-9320d8e481f0
private void generateRandoms(){ arrivals=new ArrivalGenerator(n,lambda).getArrival(); etc=new ETCGenerator(m,n,TH,MH).getETC(); }
3500be93-b276-4421-a239-442db179776f
public void newSimulation(boolean generateRandoms){ makespan=0; sigma=0; if(generateRandoms) generateRandoms(); for(int i=0;i<m;i++){ mat[i]=0; p[i].clear(); } }
45a618ec-4424-4f5c-b7d6-cedbd240456c
public void setHeuristic(Heuristic h){ this.eng.h=h; }
3dca9677-676b-4f0f-bf56-cfccbf70a141
public long getMakespan() { return makespan; }
4627eb11-50fe-40ed-8466-7165350acfe9
public int[] getArrivals() { return arrivals; }
da1d9536-4152-4c33-862a-1fed85b4c41d
public int[][] getEtc() { return etc; }
0a29590f-c2aa-4007-b493-ed3e531244fe
public void mapTask(Task t, int machine){ t.set_eTime(etc[t.tid][machine]); t.set_cTime( mat[machine]+etc[t.tid][machine] ); p[machine].offer(t); mat[machine]=t.cTime; }
f299c138-2960-4a6b-a024-70cfdce34598
public void simulate(){ /*tick represents the current time*/ int tick=0; Vector<Task> metaSet=new Vector<Task>(S); int i1=0; int i2=S; /*Initialization*/ /*Add the first S tasks to the meta set and schedule them*/ for(int i=i1;i<i2;i++){ Task t=new Task(arrivals[i],i); metaSet.add(t); } i1=i2; i2=(int) min(i1+S, arrivals.length); /*Set tick to the time of the first mapping event*/ tick=arrivals[i1-1]; eng.schedule(metaSet,tick); /*Set tick to the time of the next mapping event*/ tick=arrivals[i2-1]; /*Simulation Loop*/ do{ /*Set the current tick value*/ if(i2==i1){ tick=Integer.MAX_VALUE; /*Remove all the completed tasks from all the machines*/ removeCompletedTasks(tick); break; } else{ /*The time at which the next mapping event takes place*/ tick=arrivals[i2-1]; /*Remove all the completed tasks from all the machines*/ removeCompletedTasks(tick); } /**/ /*Collect next S OR (i2-i1) tasks to the meta set and schedule them*/ metaSet=new Vector<Task>(i2-i1); for(int i=i1;i<i2;i++){ Task t=new Task(arrivals[i],i); metaSet.add(t); } eng.schedule(metaSet, tick); /**/ /*Set values for next iteration.*/ i1=i2; i2=(int) min(i1+S, arrivals.length); /**/ }while(!discontinueSimulation()); }
bd4b86b8-4a29-4b45-a973-de9fe76ecd53
private void removeCompletedTasks(int currentTime){ for(int i=0;i<this.m;i++){ if(!p[i].isEmpty()){ Task t=p[i].peek(); while(t.cTime<=currentTime){ sigma+=t.cTime; makespan=max(makespan,t.cTime); //out.println("Removing task "+t.tid+" at time "+currentTime);//////////////////////// t=p[i].poll(); if(!p[i].isEmpty()) t=p[i].peek(); else break; } } } }
d7b5a908-e204-4221-9838-7972b6579967
private boolean discontinueSimulation(){ boolean result=true; for(int i=0;i<this.m && result;i++) result=result && p[i].isEmpty(); return result; }
b00b293f-9588-49bb-a46e-616bd551cd79
private long max(long a,long b){ if(a>b) return a; else return b; }
836542b9-8143-4f0f-a763-873949225d03
private long min(long a,long b){ if(a<b) return a; else return b; }
624af9d4-859a-4cb2-ad76-b6ac8cb5c75f
public SchedulingEngine(SimulatorEngine sim,Heuristic heuristic){ h=heuristic; this.sim=sim; }
c1a96410-087c-4f31-97d9-e69fc0c0ee23
public void schedule(Vector<Task> metaSet,int currentTime){ /*If any machine has zero assigned tasks then set mat[] for that machine to be the current time.*/ for(int i=0;i<sim.m;i++){ if(sim.p[i].isEmpty()){ sim.mat[i]=currentTime; } } if(h==Heuristic.MET) schedule_MET(metaSet,currentTime); else if(h==Heuristic.MCT) schedule_MCT(metaSet,currentTime); else if(h==Heuristic.MinMin) schedule_MinMin(metaSet,currentTime); else if(h==Heuristic.Sufferage) schedule_Sufferage(metaSet,currentTime); else if(h==Heuristic.MinMean) schedule_MinMean(metaSet,currentTime); else if(h==Heuristic.MaxMin) schedule_MaxMin(metaSet,currentTime); else if(h==Heuristic.MinVar) schedule_MinVar(metaSet,currentTime); else if(h==Heuristic.NovelI) schedule_NovelI(metaSet, currentTime); }
a566bc2d-79fd-498f-b606-c11a4906b243
private void schedule_MET(Vector<Task> metaSet,int currentTime){ int minExecTime=Integer.MAX_VALUE; int machine=0; for(int i=0;i<metaSet.size();i++){ Task t=metaSet.elementAt(i); for(int j=0;j<sim.m;j++){ if( sim.etc[t.tid][j] < minExecTime){ minExecTime=sim.etc[t.tid][j]; machine=j; } } sim.mapTask(t, machine); //out.println("Adding task "+t.tid+" to machine "+machine+". Completion time = "+t.cTime+" @time "+currentTime);////// } //out.println("________Return from schedule_________");/////////////// }
3b74b3cc-d03d-43fc-bca4-dea5e2e42ebb
private void schedule_MCT(Vector<Task> metaSet,int currentTime){ int minComplTime=Integer.MAX_VALUE; int machine=0; for(int i=0;i<metaSet.size();i++){ Task t=metaSet.elementAt(i); for(int j=0;j<sim.m;j++){ if( sim.etc[t.tid][j] + sim.mat[j] < minComplTime){ minComplTime=sim.etc[t.tid][j] + sim.mat[j]; machine=j; } } sim.mapTask(t, machine); //out.println("Adding task "+t.tid+" to machine "+machine+". Completion time = "+t.cTime+" @time "+currentTime);////// } //out.println("________Return from schedule_________");/////////////// }
0804efe4-932c-4e8e-9d84-c135465bfd01
private void schedule_MinMin(Vector<Task> metaSet, int currentTime){ /*We do not actually delete the task from the meta-set rather mark it as removed*/ boolean[] isRemoved=new boolean[metaSet.size()]; /*Matrix to contain the completion time of each task in the meta-set on each machine.*/ int c[][]=schedule_MinMinHelper(metaSet); int i=0; int tasksRemoved=0; do{ int minTime=Integer.MAX_VALUE; int machine=-1; int taskNo=-1; /*Find the task in the meta set with the earliest completion time and the machine that obtains it.*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; for(int j=0;j<sim.m;j++){ if(c[i][j]<minTime){ minTime=c[i][j]; machine=j; taskNo=i; } } } Task t=metaSet.elementAt(taskNo); sim.mapTask(t, machine); /*Mark this task as removed*/ tasksRemoved++; isRemoved[taskNo]=true; //metaSet.remove(taskNo); /*Update c[][] Matrix for other tasks in the meta-set*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; else{ c[i][machine]=sim.mat[machine]+sim.etc[metaSet.get(i).tid][machine]; } } }while(tasksRemoved!=metaSet.size()); }
44ba7a7a-1341-45a0-9704-081b09c27290
private void schedule_MaxMin(Vector<Task> metaSet, int currentTime){ /*We do not actually delete the task from the meta-set rather mark it as removed*/ boolean[] isRemoved=new boolean[metaSet.size()]; /*Matrix to contain the completion time of each task in the meta-set on each machine.*/ int c[][]=schedule_MinMinHelper(metaSet); int i=0; /*Minimum Completion Time of the ith task in the meta set*/ int[] minComplTime=new int[metaSet.size()]; int[] minComplMachine=new int[metaSet.size()]; int tasksRemoved=0; do{ int minTime=Integer.MAX_VALUE; int machine=-1; int taskNo=-1; /*Find the task in the meta set with the earliest completion time and the machine that obtains it.*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; for(int j=0;j<sim.m;j++){ if(c[i][j]<minTime){ minTime=c[i][j]; machine=j; } } minComplTime[i]=minTime; minComplMachine[i]=machine; minTime=Integer.MAX_VALUE; machine=-1; } /*Find the task which has the maximum minimum completion time*/ int maxMinComplTime=Integer.MIN_VALUE; for(int l=0;l<metaSet.size();l++){ if(maxMinComplTime<minComplTime[l]){ maxMinComplTime=minComplTime[l]; taskNo=l; } } Task t=metaSet.elementAt(taskNo); machine=minComplMachine[taskNo]; sim.mapTask(t, machine); /*Mark this task as removed*/ tasksRemoved++; isRemoved[taskNo]=true; //metaSet.remove(taskNo); /*Update c[][] Matrix for other tasks in the meta-set*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; else{ c[i][machine]=sim.mat[machine]+sim.etc[metaSet.get(i).tid][machine]; } } }while(tasksRemoved!=metaSet.size()); }
e1d4a562-7f7c-4033-91e4-7e9643749326
private int[][] schedule_MinMinHelper(Vector<Task> metaSet){ int c[][]=new int[metaSet.size()][sim.m]; int i=0; for(Iterator it=metaSet.iterator();it.hasNext();){ Task t=(Task)it.next(); for(int j=0;j<sim.m;j++){ c[i][j]=sim.mat[j]+sim.etc[t.tid][j]; } i++; } return c; }
a014f6cf-6014-4c88-ac43-004bb9ee25b0
private void schedule_Sufferage(Vector<Task> metaSet, int currentTime) { /*We don't directly add the tasks to the p[] matrix of simulator rather add in this copy first*/ Vector<TaskWrapper> pCopy[]=new Vector[sim.m]; /*Copy of mat matrix*/ int[] matCopy=new int[sim.m]; for(int i=0;i<sim.m;i++){ matCopy[i]=sim.mat[i]; /*Also initialize the processors Copy , pCopy[]*/ pCopy[i]=new Vector<TaskWrapper>(4); } /*assigned[j] =true tells that machine j has been assigned a task.*/ boolean assigned[]=new boolean[sim.m]; /*We do not actually delete the task from the meta-set rather mark it as removed*/ boolean[] isRemoved=new boolean[metaSet.size()]; /*Matrix to contain the completion time of each task in the meta-set on each machine.*/ int c[][]=schedule_MinMinHelper(metaSet); int i=0; /*Sufferage value of all tasks*/ int[] sufferage=new int[metaSet.size()]; int tasksRemoved=0; do{ int minTime1=Integer.MAX_VALUE; int minTime2=Integer.MAX_VALUE; int machine1=-1; int machine2=-1; /*For tasks in the meta set,find machine on which it has the earliest and 2nd earliest completion time*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; /*Earliest completion time machine*/ for(int j=0;j<sim.m;j++){ if(c[i][j]<minTime1){ minTime1=c[i][j]; machine1=j; } } /*2nd earliest completion time machine*/ for(int j=0;j<sim.m;j++){ if(j!=machine1 && c[i][j]<minTime2 ){ minTime2=c[i][j]; machine2=j; } } sufferage[i]=minTime2-minTime1; Task t=metaSet.elementAt(i); if(!assigned[machine1]){ mapTaskCopy(t,machine1,pCopy,matCopy,i); /*Mark this task as removed*/ tasksRemoved++; isRemoved[i]=true; //metaSet.remove(taskNo); } else{ for(Iterator it=pCopy[machine1].iterator();it.hasNext();){ TaskWrapper tw=(TaskWrapper)it.next(); if(sufferage[tw.getIndex()] < sufferage[i]){ Task task=tw.getTask(); int index=tw.getIndex(); /*Unassign this task from machine1*/ pCopy[machine1].remove(tw); /*Update matCopy[] matrix*/ matCopy[machine1]-=sim.etc[task.tid][machine1]; /*Add it back to the meta set*/ tasksRemoved--; isRemoved[index]=false; /*Assign the current task to the machine*/ mapTaskCopy(t,machine1,pCopy,matCopy,i); /*Mark this task as removed*/ tasksRemoved++; isRemoved[i]=true; } } } /*Update c[][] Matrix for other tasks in the meta-set*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; else{ c[i][machine1]=matCopy[machine1]+sim.etc[metaSet.get(i).tid][machine1]; } } } }while(tasksRemoved!=metaSet.size()); /*Copy matCopy[] and pCopy[] back to original matrices*/ for(i=0;i<sim.m;i++){ for(int j=0;j<pCopy[i].size();j++){ TaskWrapper tbu=pCopy[i].elementAt(j); sim.mapTask(tbu.getTask(), i); } } /*By doing this we are preserving the order in which tasks should have been mapped to the machines*/ System.arraycopy(matCopy, 0, sim.mat, 0, sim.m); }
e782999c-d0ac-4ff0-90a7-11314a820e9e
private void mapTaskCopy(Task t, int machine, Vector<TaskWrapper> pCopy[], int mat[],int index){ t.set_eTime(sim.etc[t.tid][machine]); t.set_cTime( mat[machine]+sim.etc[t.tid][machine] ); TaskWrapper tw=new TaskWrapper(index,t); pCopy[machine].add(tw); mat[machine]=t.cTime; }
6e1a4d0b-1dcf-4505-a56c-a0710aa18491
private void schedule_MinMean(Vector<Task> metaSet, int currentTime) { /*We don't directly add the tasks to the p[] matrix of simulator rather add in this copy first*/ Vector<TaskWrapper> pCopy[]=new Vector[sim.m]; /*Copy of mat matrix*/ int[] matCopy=new int[sim.m]; for(int i=0;i<sim.m;i++){ matCopy[i]=sim.mat[i]; /*Also initialize the processors Copy , pCopy[]*/ pCopy[i]=new Vector<TaskWrapper>(4); } /*First schedule that tasks according to min-min*/ schedule_MinMinCopy(metaSet,currentTime,pCopy,matCopy); /*Find avg completion time for each machine*/ long sigmaComplTime=0; long avgComplTime=0; for(int i=0;i<sim.m;i++) sigmaComplTime+=matCopy[i]; avgComplTime=sigmaComplTime/sim.m; int k=0; /*Reshufffle tasks from machines which have higher completion time than average to lower compl time machines*/ for(int i=0;i<sim.m;i++){ if(matCopy[i]<=avgComplTime)continue; k=0; while(k+1<=pCopy[i].size()){ TaskWrapper tw=pCopy[i].elementAt(k); Task t=tw.getTask(); /*Remap this task to another machine with completion time less than average completion time such that the difference of the new completion time of the machine and the average comple- -tion time becomes the minimum. This is analogous to best-fit algorithm */ int delta=Integer.MIN_VALUE; int machine=i; for(int j=0;j<sim.m;j++){ if(j==i || matCopy[j]>=avgComplTime)continue; if(( matCopy[j]+sim.etc[t.tid][j] < avgComplTime) && Math.abs( matCopy[j]+sim.etc[t.tid][j] - avgComplTime) > delta){ delta= (int) Math.abs( matCopy[j]+sim.etc[t.tid][j] - avgComplTime); machine=j; } } /*Map the task to the new machine*/ if(machine!=i){ pCopy[i].remove(tw); matCopy[i]-=sim.etc[t.tid][i]; mapTaskCopy(t,machine,pCopy,matCopy,tw.getIndex()); /*Note that the new avg completion time may be different from the old one*/ //sigmaComplTime-=sim.etc[t.tid][i]; //sigmaComplTime+=sim.etc[t.tid][machine]; //avgComplTime=sigmaComplTime/sim.m; /*Not included because it increases makespan slightly*/ } k++; } } /*Copy matCopy[] and pCopy[] back to original matrices*/ for(int i=0;i<sim.m;i++){ for(int j=0;j<pCopy[i].size();j++){ TaskWrapper tbu=pCopy[i].elementAt(j); sim.mapTask(tbu.getTask(), i); } } /*By doing this we are preserving the order in which tasks should have been mapped to the machines*/ System.arraycopy(matCopy, 0, sim.mat, 0, sim.m); }
803d299c-2d19-47e3-bcdc-d792a88896a7
private void schedule_MinMinCopy(Vector<Task> metaSet, int currentTime, Vector<TaskWrapper>[] pCopy, int[] matCopy){ /*We do not actually delete the task from the meta-set rather mark it as removed*/ boolean[] isRemoved=new boolean[metaSet.size()]; /*Matrix to contain the completion time of each task in the meta-set on each machine.*/ int c[][]=schedule_MinMinCopyHelper(metaSet,matCopy); int i=0; int tasksRemoved=0; do{ int minTime=Integer.MAX_VALUE; int machine=-1; int taskNo=-1; /*Find the task in the meta set with the earliest completion time and the machine that obtains it.*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; for(int j=0;j<sim.m;j++){ if(c[i][j]<minTime){ minTime=c[i][j]; machine=j; taskNo=i; } } } Task t=metaSet.elementAt(taskNo); this.mapTaskCopy(t,machine,pCopy,matCopy,taskNo); /*Mark this task as removed*/ tasksRemoved++; isRemoved[taskNo]=true; //metaSet.remove(taskNo); /*Update c[][] Matrix for other tasks in the meta-set*/ for(i=0;i<metaSet.size();i++){ if(isRemoved[i])continue; else{ c[i][machine]=matCopy[machine]+sim.etc[metaSet.get(i).tid][machine]; } } }while(tasksRemoved!=metaSet.size()); }
044c18d1-1bf2-49cb-91ef-921f674f390a
private int[][] schedule_MinMinCopyHelper(Vector<Task> metaSet, int[] matCopy){ int c[][]=new int[metaSet.size()][sim.m]; int i=0; for(Iterator it=metaSet.iterator();it.hasNext();){ Task t=(Task)it.next(); for(int j=0;j<sim.m;j++){ c[i][j]=matCopy[j]+sim.etc[t.tid][j]; } i++; } return c; }
dc9c7848-97e3-4dfc-a33a-d6fe30a094f1
private void schedule_MinVar(Vector<Task> metaSet, int currentTime) { /*We don't directly add the tasks to the p[] matrix of simulator rather add in this copy first*/ Vector<TaskWrapper> pCopy[]=new Vector[sim.m]; /*Copy of mat matrix*/ int[] matCopy=new int[sim.m]; for(int i=0;i<sim.m;i++){ matCopy[i]=sim.mat[i]; /*Also initialize the processors Copy , pCopy[]*/ pCopy[i]=new Vector<TaskWrapper>(4); } /*First schedule that tasks according to min-min*/ schedule_MinMinCopy(metaSet,currentTime,pCopy,matCopy); /*Find avg completion time for each machine*/ long sigmaComplTime=0; long avgComplTime=0; for(int i=0;i<sim.m;i++) sigmaComplTime+=matCopy[i]; avgComplTime=sigmaComplTime/sim.m; int k=0; /*Reshuffle tasks so that the variance decreases*/ for(int i=0;i<sim.m;i++){ if(matCopy[i]<=avgComplTime)continue; k=0; while(k+1<=pCopy[i].size()){ TaskWrapper tw=pCopy[i].elementAt(k); Task t=tw.getTask(); int deltaVar=0; int minDeltaVar=Integer.MAX_VALUE; long newSigmaComplTime=sigmaComplTime; long newAvgComplTime=avgComplTime; int machine=i; int delta=Integer.MIN_VALUE; for(int j=0;j<sim.m;j++){ if(j==i || matCopy[j]>=avgComplTime)continue; deltaVar=0; newSigmaComplTime-=sim.etc[t.tid][i]; newSigmaComplTime+=sim.etc[t.tid][j]; newAvgComplTime=newSigmaComplTime/sim.m; deltaVar-=(int) Math.pow((matCopy[i] - avgComplTime),2); deltaVar+=(int) Math.pow((matCopy[i]-sim.etc[t.tid][i]-newAvgComplTime),2); deltaVar-=(int) Math.pow((matCopy[j]-avgComplTime),2); deltaVar+=(int) Math.pow((matCopy[j]+sim.etc[t.tid][j]-newAvgComplTime),2); if(( matCopy[j]+sim.etc[t.tid][j] < avgComplTime) && Math.abs( matCopy[j]+sim.etc[t.tid][j] - avgComplTime) > delta && deltaVar<0 && deltaVar<minDeltaVar){ minDeltaVar=deltaVar; delta= (int) Math.abs( matCopy[j]+sim.etc[t.tid][j] - avgComplTime); machine=j; } newSigmaComplTime=sigmaComplTime; newAvgComplTime=avgComplTime; } /*Map the task to the new machine*/ if(machine!=i){ pCopy[i].remove(tw); matCopy[i]-=sim.etc[t.tid][i]; mapTaskCopy(t,machine,pCopy,matCopy,tw.getIndex()); /*Note that the new avg completion time may be different from the old one*/ sigmaComplTime-=sim.etc[t.tid][i]; sigmaComplTime+=sim.etc[t.tid][machine]; avgComplTime=sigmaComplTime/sim.m; } k++; } } /*Copy matCopy[] and pCopy[] back to original matrices*/ for(int i=0;i<sim.m;i++){ for(int j=0;j<pCopy[i].size();j++){ TaskWrapper tbu=pCopy[i].elementAt(j); sim.mapTask(tbu.getTask(), i); } } /*By doing this we are preserving the order in which tasks should have been mapped to the machines*/ System.arraycopy(matCopy, 0, sim.mat, 0, sim.m); }
3610259a-b732-4ebb-938b-07546ff4d3bc
private void schedule_NovelI(Vector<Task> metaSet, int currentTime){ }
96ebdd89-3e68-4363-a560-06a27ac1cdb3
public RandomGenerator(double lambda){ r=new Random(); this.lambda=lambda; }
efabaafd-283f-48a6-a881-f5d13861c843
public int nextPoisson() { double L = Math.exp(-lambda); double p = 1.0; int k = 0; do { k++; p *= r.nextDouble(); } while (p > L); return k - 1; }
5aa27df2-bf12-4123-8aac-c96a4d91056b
public static void main(String...args){ int lambda=2; RandomGenerator rg=new RandomGenerator(lambda); int sum=0; double n_trials=100.0; for(int i=0;i<n_trials;i++){ int a=rg.nextPoisson(); sum+=a; out.print(a); } out.println("\nsum "+sum); out.println("avg: "+(double)sum/n_trials+ " -> lambda: "+lambda); }
8de52407-cb0e-4238-b103-f20c2b7bc017
private TaskHeterogeneity(int h){ this.h=h; }
27a3fff7-ce96-445f-bf33-40b0b00e6215
public int getNumericValue(){ return h; }
ed4a95ec-4684-40c5-b1f5-1efc899a850c
public TaskWrapper(int index, Task task){ i=index; t=task; }
84b73db3-73ca-484b-88cc-a49679e74423
public int getIndex() { return i; }
67c2e7a1-5673-4527-bdf6-28a4ee6486f6
public Task getTask() { return t; }
0069bc67-de50-4ec9-8ef2-fbb4827253ad
public static void main(String...args){ long t1=System.currentTimeMillis(); /*Specify the parameters here*/ int NUM_MACHINES=29; int NUM_TASKS=500; double ARRIVAL_RATE=19; int metaSetSize=29; Heuristic h=null; TaskHeterogeneity TH=null; MachineHeterogeneity MH=null; Heuristic HEURISTIC=null; TaskHeterogeneity th=TH.HIGH; MachineHeterogeneity mh=MH.HIGH; int no_of_simulations=4000; /*Specify the parameters here*/ Heuristic[] htype=Heuristic.values(); long sigmaMakespan[]=new long[htype.length]; long avgMakespan=0; SimulatorEngine se=new SimulatorEngine(NUM_MACHINES, NUM_TASKS, ARRIVAL_RATE, metaSetSize,null,th, mh); for(int i=0;i<no_of_simulations;i++){ se.newSimulation(true); for(int j=0;j<htype.length;j++){ se.setHeuristic(htype[j]); //out.println(Arrays.deepToString(se.getEtc()));////////// //out.println(Arrays.toString(se.getArrivals()));///////// se.simulate(); //out.println("Makespan ="+se.getMakespan() +"strategy:"+htype[j].toString());/////////////// sigmaMakespan[j]+=se.getMakespan(); se.newSimulation(false); } } for(int j=0;j<htype.length;j++){ avgMakespan=sigmaMakespan[j]/no_of_simulations; String hName=htype[j].toString(); String tmp=(String.format("%9s",hName)); DecimalFormat myFormatter = new DecimalFormat("00000000"); String output=myFormatter.format(avgMakespan); out.println("Avg makespan for "+tmp+" heuristic for "+no_of_simulations+ " simulations is = "+output); } long t2=System.currentTimeMillis(); out.println("Total time taken in the simulation = "+(t2-t1)/1000+" sec."); }
d4548062-a312-4dfd-af35-5331b8ce255f
public ArrivalGenerator(int NUM_TASKS, double Lambda){ arrival_time=new int[NUM_TASKS]; lambda=Lambda; }
19f48f3f-6682-4183-9a40-93d3769fafaf
public ArrivalGenerator ArrivalGenerator(int NUM_TASKS, double Lambda){ arrival_time=new int[NUM_TASKS]; lambda=Lambda; return this; }
d62fd4e3-363a-4867-9045-665cc10690f3
private void generateArrival(){ RandomGenerator r= new RandomGenerator(lambda); arrival_time[0]=r.nextPoisson(); for(int i=1;i<arrival_time.length;i++){ arrival_time[i]=arrival_time[i-1]+r.nextPoisson(); } }
aeacad7b-8c44-46f5-ae4b-7ac99d8f69c0
public int[] getArrival(){ generateArrival(); return arrival_time; }