To solve the optimization problem described, we will first define the decision variables and the objective function. Let's denote:

- $x$ as the number of regular machines.
- $y$ as the number of advanced machines.

The objective is to minimize the total cost, which can be calculated as $1000x + 10000y$, since a regular machine costs $1000 and an advanced machine costs $10000.

We have two main constraints:

1. **Task Completion Requirement**: The factory needs to complete at least 120 tasks per hour. Given that a regular machine performs 5 tasks per hour and an advanced machine performs 25 tasks per hour, the constraint can be represented as $5x + 25y \geq 120$.

2. **Worker Limitation**: There is a maximum of 20 workers available. Since a regular machine requires 2 workers and an advanced machine requires 5 workers, this constraint can be represented as $2x + 5y \leq 20$.

Additionally, we need to ensure that the number of machines is non-negative since we cannot have a negative number of machines. Thus, $x \geq 0$ and $y \geq 0$.

The optimization problem can be formulated as follows:

Minimize: $1000x + 10000y$

Subject to:
- $5x + 25y \geq 120$
- $2x + 5y \leq 20$
- $x, y \geq 0$

Now, let's translate this into Gurobi code in Python:

```python
from gurobipy import *

# Create a model
m = Model("Boarstone_Factory_Optimization")

# Decision variables
x = m.addVar(name='regular_machines', vtype=GRB.INTEGER, lb=0)
y = m.addVar(name='advanced_machines', vtype=GRB.INTEGER, lb=0)

# Objective function: Minimize cost
m.setObjective(1000*x + 10000*y, GRB.MINIMIZE)

# Constraints
m.addConstr(5*x + 25*y >= 120, name='task_requirement')
m.addConstr(2*x + 5*y <= 20, name='worker_limitation')

# Optimize the model
m.optimize()

# Print solution
if m.status == GRB.OPTIMAL:
    print(f"Optimal solution found: {x.varName} = {x.x}, {y.varName} = {y.x}")
else:
    print("No optimal solution found")

```