public static void Main(string[] args) { int mineral, gas, supply; Data data = new Data(); if (args.Length != 3) { System.Console.WriteLine("Usage: ResourceAllocation #mineral #gas #supply"); //return; mineral = 1000; gas = 700; supply = 19; } else { mineral = Convert.ToInt32(args[0]); gas = Convert.ToInt32(args[1]); supply = Convert.ToInt32(args[2]); } int maxSize = Math.Max(mineral / 25, Math.Max(gas / 25, supply)); var domain = new ghost.Domain(maxSize, 0); var listUnits = MakeTerranUnits(domain); var setUnits = new SetVariables(listUnits); var constraints = new List <Constraint> { new MineralConstraint(setUnits, mineral), new GasConstraint(setUnits, gas), new SupplyConstraint(setUnits, supply) }; var objective = new MaxDPS("max DPS", mineral, gas, supply); var solver = new ghost.Solver <Variable, SetVariables, Constraint>(setUnits, constraints, objective); Console.WriteLine("Start solving trivial test"); solver.solve(20, 150); int mineralUsed = 0; int gasUsed = 0; double supplyUsed = 0.0; double DPS = 0.0; for (int i = 0; i < setUnits.GetNumberVariables(); ++i) { mineralUsed += setUnits.GetValue(i) * data.Dataset[setUnits.Name(i)].CostMineral; gasUsed += setUnits.GetValue(i) * data.Dataset[setUnits.Name(i)].CostGas; supplyUsed += setUnits.GetValue(i) * data.Dataset[setUnits.Name(i)].CostSupply; if (data.Dataset[setUnits.Name(i)].GroundAttack > 0) { DPS += setUnits.GetValue(i) * ((double)data.Dataset[setUnits.Name(i)].GroundAttack / data.Dataset[setUnits.Name(i)].GroundCooldown); } } DPS *= 24; Console.WriteLine("DPS = " + DPS); Console.WriteLine("Mineral left: " + (mineral - mineralUsed) + ", gas left: " + (gas - gasUsed) + ", supply left: " + (supply - supplyUsed)); }
public static void Main( string[] args ) { int mineral, gas, supply; Data data = new Data(); if( args.Length != 3 ) { System.Console.WriteLine( "Usage: ResourceAllocation #mineral #gas #supply" ); //return; mineral = 20000; gas = 14000; supply = 380; } else { mineral = Convert.ToInt32( args[ 0 ] ); gas = Convert.ToInt32( args[ 1 ] ); supply = Convert.ToInt32( args[ 2 ] ); } int maxSize = Math.Max( mineral / 25, Math.Max( gas / 25, supply ) ); var domain = new ghost.Domain( maxSize, 0 ); var listUnits = MakeTerranUnits( domain ); var setUnits = new SetVariables( listUnits ); var constraints = new List< Constraint > { new MineralConstraint( setUnits, mineral ), new GasConstraint( setUnits, gas ), new SupplyConstraint( setUnits, supply ) }; var objective = new MaxDPS( "max DPS", mineral, gas, supply ); var solver = new ghost.Solver< Variable, SetVariables, Constraint >( setUnits, constraints, objective ); Console.WriteLine( "Start solving trivial test" ); solver.solve( 100, 2000 ); int mineralUsed = 0; int gasUsed = 0; double supplyUsed = 0.0; double DPS = 0.0; for( int i = 0 ; i < setUnits.GetNumberVariables() ; ++i ) { mineralUsed += setUnits.GetValue( i ) * data.Dataset[ setUnits.Name( i ) ].CostMineral; gasUsed += setUnits.GetValue( i ) * data.Dataset[ setUnits.Name( i ) ].CostGas; supplyUsed += setUnits.GetValue( i ) * data.Dataset[ setUnits.Name( i ) ].CostSupply; if( data.Dataset[ setUnits.Name( i ) ].GroundAttack > 0 ) DPS += setUnits.GetValue( i ) * ( (double)data.Dataset[ setUnits.Name( i ) ].GroundAttack / data.Dataset[ setUnits.Name( i ) ].GroundCooldown ); } DPS *= 24; Console.WriteLine( "DPS = " + DPS ); Console.WriteLine( "Mineral left: " + (mineral - mineralUsed) + ", gas left: " + (gas - gasUsed) + ", supply left: " + (supply - supplyUsed) ); }
static void Main( string[] args ) { var unbuildables = new List< SetVariables.Point > { new SetVariables.Point( 7, 12 ), new SetVariables.Point( 7, 13 ), new SetVariables.Point( 7, 14 ), new SetVariables.Point( 7, 15 ), new SetVariables.Point( 8, 10 ), new SetVariables.Point( 8, 11 ), new SetVariables.Point( 8, 12 ), new SetVariables.Point( 8, 13 ), new SetVariables.Point( 8, 14 ), new SetVariables.Point( 8, 15 ), new SetVariables.Point( 9, 10 ), new SetVariables.Point( 9, 11 ), new SetVariables.Point( 9, 12 ), new SetVariables.Point( 9, 13 ), new SetVariables.Point( 9, 14 ), new SetVariables.Point( 9, 15 ), new SetVariables.Point( 10, 8 ), new SetVariables.Point( 10, 9 ), new SetVariables.Point( 10, 10 ), new SetVariables.Point( 10, 11 ), new SetVariables.Point( 10, 12 ), new SetVariables.Point( 10, 13 ), new SetVariables.Point( 10, 14 ), new SetVariables.Point( 10, 15 ), new SetVariables.Point( 11, 8 ), new SetVariables.Point( 11, 9 ), new SetVariables.Point( 11, 10 ), new SetVariables.Point( 11, 11 ), new SetVariables.Point( 11, 12 ), new SetVariables.Point( 11, 13 ), new SetVariables.Point( 11, 14 ), new SetVariables.Point( 11, 15 ) }; var domain = new ghost.Domain( 16 * 12, 0 ); var listBuildings = MakeTerranBuildings( domain ); var setBuildings = new SetVariables( listBuildings, 12, 16, new SetVariables.Point( 11, 7 ), new SetVariables.Point( 6, 15 ) ); setBuildings.Unbuildable( unbuildables ); var constraints = new List< Constraint > { new OverLap( setBuildings ), new Buildable( setBuildings ), new WallShape( setBuildings ), new StartingTargetTiles( setBuildings ) }; var objective = new GapObjective(); var solver = new ghost.Solver< Variable, SetVariables, Constraint >( setBuildings, constraints, objective ); Console.WriteLine( "Start solving trivial test" ); solver.solve( 20, 150, false ); // 3.4 GHz, mono 20,150 7 tours 44 iterations // C++ 12 tours 400 iteratons }
static void Main(string[] args) { var unbuildables = new List <SetVariables.Point> { new SetVariables.Point(7, 12), new SetVariables.Point(7, 13), new SetVariables.Point(7, 14), new SetVariables.Point(7, 15), new SetVariables.Point(8, 10), new SetVariables.Point(8, 11), new SetVariables.Point(8, 12), new SetVariables.Point(8, 13), new SetVariables.Point(8, 14), new SetVariables.Point(8, 15), new SetVariables.Point(9, 10), new SetVariables.Point(9, 11), new SetVariables.Point(9, 12), new SetVariables.Point(9, 13), new SetVariables.Point(9, 14), new SetVariables.Point(9, 15), new SetVariables.Point(10, 8), new SetVariables.Point(10, 9), new SetVariables.Point(10, 10), new SetVariables.Point(10, 11), new SetVariables.Point(10, 12), new SetVariables.Point(10, 13), new SetVariables.Point(10, 14), new SetVariables.Point(10, 15), new SetVariables.Point(11, 8), new SetVariables.Point(11, 9), new SetVariables.Point(11, 10), new SetVariables.Point(11, 11), new SetVariables.Point(11, 12), new SetVariables.Point(11, 13), new SetVariables.Point(11, 14), new SetVariables.Point(11, 15) }; var domain = new ghost.Domain(16 * 12, 0); var listBuildings = MakeTerranBuildings(domain); var setBuildings = new SetVariables(listBuildings, 12, 16, new SetVariables.Point(11, 7), new SetVariables.Point(6, 15)); setBuildings.Unbuildable(unbuildables); var constraints = new List <Constraint> { new OverLap(setBuildings), new Buildable(setBuildings), new WallShape(setBuildings), new StartingTargetTiles(setBuildings) }; var objective = new GapObjective(); var solver = new ghost.Solver <Variable, SetVariables, Constraint>(setBuildings, constraints, objective); Console.WriteLine("Start solving trivial test"); solver.solve(20, 150, false); // 3.4 GHz, mono 20,150 7 tours 44 iterations // C++ 12 tours 400 iteratons }